1
0
mirror of https://github.com/rancher/rke.git synced 2025-06-28 16:28:26 +00:00
rke/services/kubeapi.go

75 lines
2.5 KiB
Go
Raw Normal View History

2017-10-29 09:45:21 +00:00
package services
import (
2017-11-14 18:11:21 +00:00
"fmt"
2017-10-29 09:45:21 +00:00
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/rancher/rke/docker"
2017-10-29 09:45:21 +00:00
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/pki"
2017-12-05 16:55:58 +00:00
"github.com/rancher/types/apis/management.cattle.io/v3"
2017-10-29 09:45:21 +00:00
)
func runKubeAPI(host *hosts.Host, etcdHosts []*hosts.Host, kubeAPIService v3.KubeAPIService, authorizationMode string) error {
etcdConnString := GetEtcdConnString(etcdHosts)
imageCfg, hostCfg := buildKubeAPIConfig(host, kubeAPIService, etcdConnString, authorizationMode)
2017-11-28 17:45:24 +00:00
return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeAPIContainerName, host.Address, ControlRole)
2017-10-29 09:45:21 +00:00
}
func removeKubeAPI(host *hosts.Host) error {
2017-11-28 17:45:24 +00:00
return docker.DoRemoveContainer(host.DClient, KubeAPIContainerName, host.Address)
}
func buildKubeAPIConfig(host *hosts.Host, kubeAPIService v3.KubeAPIService, etcdConnString, authorizationMode string) (*container.Config, *container.HostConfig) {
2017-10-29 09:45:21 +00:00
imageCfg := &container.Config{
Image: kubeAPIService.Image,
2017-12-08 23:05:55 +00:00
Entrypoint: []string{"/opt/rke/entrypoint.sh",
"kube-apiserver",
"--insecure-bind-address=127.0.0.1",
2017-11-28 17:45:24 +00:00
"--bind-address=0.0.0.0",
2017-10-29 09:45:21 +00:00
"--insecure-port=8080",
"--secure-port=6443",
2017-10-29 09:45:21 +00:00
"--cloud-provider=",
"--allow_privileged=true",
2017-11-28 17:45:24 +00:00
"--kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname",
"--service-cluster-ip-range=" + kubeAPIService.ServiceClusterIPRange,
"--admission-control=ServiceAccount,NamespaceLifecycle,LimitRanger,PersistentVolumeLabel,DefaultStorageClass,ResourceQuota,DefaultTolerationSeconds",
2017-10-29 09:45:21 +00:00
"--runtime-config=batch/v2alpha1",
"--runtime-config=authentication.k8s.io/v1beta1=true",
"--storage-backend=etcd3",
"--etcd-servers=" + etcdConnString,
"--client-ca-file=" + pki.CACertPath,
"--tls-cert-file=" + pki.KubeAPICertPath,
"--tls-private-key-file=" + pki.KubeAPIKeyPath,
"--service-account-key-file=" + pki.KubeAPIKeyPath},
2017-10-29 09:45:21 +00:00
}
if authorizationMode == RBACAuthorizationMode {
imageCfg.Cmd = append(imageCfg.Cmd, "--authorization-mode=RBAC")
}
2017-10-29 09:45:21 +00:00
hostCfg := &container.HostConfig{
2017-12-08 23:05:55 +00:00
VolumesFrom: []string{
SidekickContainerName,
},
Binds: []string{
"/etc/kubernetes:/etc/kubernetes",
},
2017-10-29 09:45:21 +00:00
NetworkMode: "host",
RestartPolicy: container.RestartPolicy{Name: "always"},
PortBindings: nat.PortMap{
"8080/tcp": []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: "8080",
},
},
},
}
2017-11-14 18:11:21 +00:00
for arg, value := range kubeAPIService.ExtraArgs {
cmd := fmt.Sprintf("--%s=%s", arg, value)
imageCfg.Entrypoint = append(imageCfg.Entrypoint, cmd)
2017-11-14 18:11:21 +00:00
}
return imageCfg, hostCfg
2017-10-29 09:45:21 +00:00
}