1
0
mirror of https://github.com/rancher/rke.git synced 2025-07-31 06:49:54 +00:00
rke/services/kubeapi.go
galal-hussein 9974d53e57 Use Cluster structure
Use separate cluster package

Save cluster state and certs to kubernetes

Handle Remove and sync cluster state/crts

Reuse kubernetes client and combine image and version

Separate building functions and small fixes
2017-11-06 19:40:20 +02:00

55 lines
1.8 KiB
Go

package services
import (
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/rancher/rke/docker"
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/pki"
)
func runKubeAPI(host hosts.Host, etcdHosts []hosts.Host, kubeAPIService KubeAPI) error {
etcdConnString := getEtcdConnString(etcdHosts)
imageCfg, hostCfg := buildKubeAPIConfig(host, kubeAPIService, etcdConnString)
return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeAPIContainerName, host.Hostname, ControlRole)
}
func buildKubeAPIConfig(host hosts.Host, kubeAPIService KubeAPI, etcdConnString string) (*container.Config, *container.HostConfig) {
imageCfg := &container.Config{
Image: kubeAPIService.Image,
Cmd: []string{"/hyperkube",
"apiserver",
"--insecure-bind-address=0.0.0.0",
"--insecure-port=8080",
"--cloud-provider=",
"--allow_privileged=true",
"--service-cluster-ip-range=" + kubeAPIService.ServiceClusterIPRange,
"--admission-control=ServiceAccount,NamespaceLifecycle,LimitRanger,PersistentVolumeLabel,DefaultStorageClass,ResourceQuota,DefaultTolerationSeconds",
"--runtime-config=batch/v2alpha1",
"--runtime-config=authentication.k8s.io/v1beta1=true",
"--storage-backend=etcd3",
"--etcd-servers=" + etcdConnString,
"--advertise-address=" + host.AdvertiseAddress,
"--client-ca-file=" + pki.CACertPath,
"--tls-cert-file=" + pki.KubeAPICertPath,
"--tls-private-key-file=" + pki.KubeAPIKeyPath,
"--service-account-key-file=" + pki.KubeAPIKeyPath},
}
hostCfg := &container.HostConfig{
Binds: []string{
"/etc/kubernetes:/etc/kubernetes",
},
NetworkMode: "host",
RestartPolicy: container.RestartPolicy{Name: "always"},
PortBindings: nat.PortMap{
"8080/tcp": []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: "8080",
},
},
},
}
return imageCfg, hostCfg
}