From 5715e1ba0d3bdfedfecd56a3b8b6205fb7af70ab Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Mon, 27 Apr 2020 09:31:25 -0700 Subject: [PATCH] Add ability to disable kubeproxy --- pkg/agent/config/config.go | 1 + pkg/cli/cmds/server.go | 6 ++++++ pkg/cli/server/server.go | 1 + pkg/daemons/agent/agent.go | 9 +++++++-- pkg/daemons/config/types.go | 2 ++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go index 52aa894cbc..6c83905c2c 100644 --- a/pkg/agent/config/config.go +++ b/pkg/agent/config/config.go @@ -474,6 +474,7 @@ func get(envInfo *cmds.Agent) (*config.Node, error) { nodeConfig.AgentConfig.PrivateRegistry = envInfo.PrivateRegistry nodeConfig.AgentConfig.DisableCCM = controlConfig.DisableCCM nodeConfig.AgentConfig.DisableNPC = controlConfig.DisableNPC + nodeConfig.AgentConfig.DisableKubeProxy = controlConfig.DisableKubeProxy nodeConfig.AgentConfig.Rootless = envInfo.Rootless nodeConfig.DisableSELinux = envInfo.DisableSELinux diff --git a/pkg/cli/cmds/server.go b/pkg/cli/cmds/server.go index 2cda615cfb..d7847149e6 100644 --- a/pkg/cli/cmds/server.go +++ b/pkg/cli/cmds/server.go @@ -40,6 +40,7 @@ type Server struct { DefaultLocalStoragePath string DisableCCM bool DisableNPC bool + DisableKubeProxy bool ClusterInit bool ClusterReset bool EncryptSecrets bool @@ -206,6 +207,11 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command { Usage: "(components) Disable k3s default cloud controller manager", Destination: &ServerConfig.DisableCCM, }, + cli.BoolFlag{ + Name: "disable-kube-proxy", + Usage: "(components) Disable running kube-proxy", + Destination: &ServerConfig.DisableKubeProxy, + }, cli.BoolFlag{ Name: "disable-network-policy", Usage: "(components) Disable k3s default network policy controller", diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index 06afca8e11..07d5fd98f7 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -98,6 +98,7 @@ func run(app *cli.Context, cfg *cmds.Server) error { serverConfig.ControlConfig.ExtraCloudControllerArgs = cfg.ExtraCloudControllerArgs serverConfig.ControlConfig.DisableCCM = cfg.DisableCCM serverConfig.ControlConfig.DisableNPC = cfg.DisableNPC + serverConfig.ControlConfig.DisableKubeProxy = cfg.DisableKubeProxy serverConfig.ControlConfig.ClusterInit = cfg.ClusterInit serverConfig.ControlConfig.ClusterReset = cfg.ClusterReset serverConfig.ControlConfig.EncryptSecrets = cfg.EncryptSecrets diff --git a/pkg/daemons/agent/agent.go b/pkg/daemons/agent/agent.go index 1344c5224d..fa25b7d471 100644 --- a/pkg/daemons/agent/agent.go +++ b/pkg/daemons/agent/agent.go @@ -29,12 +29,15 @@ func Agent(config *config.Agent) error { defer logs.FlushLogs() startKubelet(config) - startKubeProxy(config) + + if !config.DisableKubeProxy { + return startKubeProxy(config) + } return nil } -func startKubeProxy(cfg *config.Agent) { +func startKubeProxy(cfg *config.Agent) error { argsMap := map[string]string{ "proxy-mode": "iptables", "healthz-bind-address": "127.0.0.1", @@ -53,6 +56,8 @@ func startKubeProxy(cfg *config.Agent) { logrus.Infof("Running kube-proxy %s", config.ArgString(args)) logrus.Fatalf("kube-proxy exited: %v", command.Execute()) }() + + return nil } func startKubelet(cfg *config.Agent) { diff --git a/pkg/daemons/config/types.go b/pkg/daemons/config/types.go index 696b5acc19..c8a77bc4d2 100644 --- a/pkg/daemons/config/types.go +++ b/pkg/daemons/config/types.go @@ -79,6 +79,7 @@ type Agent struct { PrivateRegistry string DisableCCM bool DisableNPC bool + DisableKubeProxy bool Rootless bool } @@ -112,6 +113,7 @@ type Control struct { DefaultLocalStoragePath string DisableCCM bool DisableNPC bool + DisableKubeProxy bool ClusterInit bool ClusterReset bool EncryptSecrets bool