2017-10-29 09:45:21 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/api/types/container"
|
2017-10-31 13:55:35 +00:00
|
|
|
"github.com/rancher/rke/docker"
|
2017-10-29 09:45:21 +00:00
|
|
|
"github.com/rancher/rke/hosts"
|
2017-10-31 13:55:35 +00:00
|
|
|
"github.com/rancher/rke/pki"
|
2017-10-29 09:45:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type KubeController struct {
|
2017-10-31 13:55:35 +00:00
|
|
|
Version string `yaml:"version"`
|
|
|
|
Image string `yaml:"image"`
|
2017-11-01 18:50:00 +00:00
|
|
|
ClusterCIDR string `yaml:"cluster_cidr"`
|
2017-10-31 13:55:35 +00:00
|
|
|
ServiceClusterIPRange string `yaml:"service_cluster_ip_range"`
|
2017-10-29 09:45:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func runKubeController(host hosts.Host, kubeControllerService KubeController) error {
|
2017-10-31 13:55:35 +00:00
|
|
|
imageCfg, hostCfg := buildKubeControllerConfig(kubeControllerService)
|
|
|
|
err := docker.DoRunContainer(imageCfg, hostCfg, KubeControllerContainerName, &host, ControlRole)
|
2017-10-29 09:45:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-10-31 13:55:35 +00:00
|
|
|
func buildKubeControllerConfig(kubeControllerService KubeController) (*container.Config, *container.HostConfig) {
|
2017-10-29 09:45:21 +00:00
|
|
|
imageCfg := &container.Config{
|
|
|
|
Image: kubeControllerService.Image + ":" + kubeControllerService.Version,
|
|
|
|
Cmd: []string{"/hyperkube",
|
|
|
|
"controller-manager",
|
|
|
|
"--address=0.0.0.0",
|
|
|
|
"--cloud-provider=",
|
2017-10-31 13:55:35 +00:00
|
|
|
"--kubeconfig=" + pki.KubeControllerConfigPath,
|
2017-10-29 09:45:21 +00:00
|
|
|
"--enable-hostpath-provisioner=false",
|
|
|
|
"--node-monitor-grace-period=40s",
|
|
|
|
"--pod-eviction-timeout=5m0s",
|
|
|
|
"--v=2",
|
|
|
|
"--allocate-node-cidrs=true",
|
2017-10-30 06:31:06 +00:00
|
|
|
"--cluster-cidr=" + kubeControllerService.ClusterCIDR,
|
2017-10-31 13:55:35 +00:00
|
|
|
"--service-cluster-ip-range=" + kubeControllerService.ServiceClusterIPRange,
|
|
|
|
"--service-account-private-key-file=" + pki.KubeAPIKeyPath,
|
|
|
|
"--root-ca-file=" + pki.CACertPath,
|
|
|
|
},
|
2017-10-29 09:45:21 +00:00
|
|
|
}
|
|
|
|
hostCfg := &container.HostConfig{
|
2017-10-31 13:55:35 +00:00
|
|
|
Binds: []string{
|
|
|
|
"/etc/kubernetes:/etc/kubernetes",
|
|
|
|
},
|
2017-10-29 09:45:21 +00:00
|
|
|
RestartPolicy: container.RestartPolicy{Name: "always"},
|
|
|
|
}
|
2017-10-31 13:55:35 +00:00
|
|
|
return imageCfg, hostCfg
|
2017-10-29 09:45:21 +00:00
|
|
|
}
|