1
0
mirror of https://github.com/rancher/rke.git synced 2025-06-03 20:49:40 +00:00
rke/services/kubeproxy.go

53 lines
1.6 KiB
Go
Raw Normal View History

2017-10-29 09:45:21 +00:00
package services
import (
"context"
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/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 runKubeproxy(ctx context.Context, host *hosts.Host, kubeproxyService v3.KubeproxyService, df hosts.DialerFactory) error {
imageCfg, hostCfg := buildKubeproxyConfig(host, kubeproxyService)
if err := docker.DoRunContainer(ctx, host.DClient, imageCfg, hostCfg, KubeproxyContainerName, host.Address, WorkerRole); err != nil {
return err
}
return runHealthcheck(ctx, host, KubeproxyPort, false, KubeproxyContainerName, df)
2017-10-29 09:45:21 +00:00
}
func removeKubeproxy(ctx context.Context, host *hosts.Host) error {
return docker.DoRemoveContainer(ctx, host.DClient, KubeproxyContainerName, host.Address)
}
2017-12-05 16:55:58 +00:00
func buildKubeproxyConfig(host *hosts.Host, kubeproxyService v3.KubeproxyService) (*container.Config, *container.HostConfig) {
2017-10-29 09:45:21 +00:00
imageCfg := &container.Config{
Image: kubeproxyService.Image,
2017-12-08 23:05:55 +00:00
Entrypoint: []string{"/opt/rke/entrypoint.sh",
"kube-proxy",
2017-10-29 09:45:21 +00:00
"--v=2",
"--healthz-bind-address=0.0.0.0",
"--kubeconfig=" + pki.GetConfigPath(pki.KubeProxyCertName),
},
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"},
Privileged: true,
}
2017-11-14 18:11:21 +00:00
for arg, value := range kubeproxyService.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
}