diff --git a/README.md b/README.md index a0afc460e0..3a22390397 100644 --- a/README.md +++ b/README.md @@ -528,6 +528,14 @@ improve the usability. First ensure you have proper setup and support for user [requirements section](https://github.com/rootless-containers/rootlesskit#setup) in rootlesskit for instructions. In short, latest Ubuntu is your best bet for this to work. +Node Labels and Taints +---------------------- + +k3s server and agent can be configured with options `--node-label` and `--node-taint` which adds set of Labels and Taints to kubelet, the two options only adds labels/taints at registration time, so they can only be added once and not changed after that, an example to add new label is: +``` +k3s server --node-label foo=bar --node-label hello=world --node-taint key1=value1:NoExecute +``` + ## Issues w/ Rootless When running rootless a new network namespace is created. This means that k3s instance is running with networking diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go index 936ffb3021..330d94fafd 100644 --- a/pkg/agent/config/config.go +++ b/pkg/agent/config/config.go @@ -337,6 +337,9 @@ func get(envInfo *cmds.Agent) (*config.Node, error) { nodeConfig.AgentConfig.ExtraKubeletArgs = envInfo.ExtraKubeletArgs nodeConfig.AgentConfig.ExtraKubeProxyArgs = envInfo.ExtraKubeProxyArgs + nodeConfig.AgentConfig.NodeTaints = envInfo.Taints + nodeConfig.AgentConfig.NodeLabels = envInfo.Labels + return nodeConfig, nil } diff --git a/pkg/cli/agent/agent.go b/pkg/cli/agent/agent.go index a239a82954..47da1e1e6b 100644 --- a/pkg/cli/agent/agent.go +++ b/pkg/cli/agent/agent.go @@ -65,6 +65,7 @@ func Run(ctx *cli.Context) error { cfg := cmds.AgentConfig cfg.Debug = ctx.GlobalBool("debug") cfg.DataDir = dataDir + cfg.Labels = append(cfg.Labels, "node-role.kubernetes.io/worker=true") contextCtx := signal.SigTermCancelContext(context.Background()) diff --git a/pkg/cli/cmds/agent.go b/pkg/cli/cmds/agent.go index 966b084073..6d0d65d22f 100644 --- a/pkg/cli/cmds/agent.go +++ b/pkg/cli/cmds/agent.go @@ -26,6 +26,8 @@ type Agent struct { AgentShared ExtraKubeletArgs cli.StringSlice ExtraKubeProxyArgs cli.StringSlice + Labels cli.StringSlice + Taints cli.StringSlice } type AgentShared struct { @@ -87,6 +89,16 @@ var ( Usage: "(agent) Customized flag for kube-proxy process", Value: &AgentConfig.ExtraKubeProxyArgs, } + NodeTaints = cli.StringSliceFlag{ + Name: "node-taint", + Usage: "(agent) Registring kubelet with set of taints", + Value: &AgentConfig.Taints, + } + NodeLabels = cli.StringSliceFlag{ + Name: "node-label", + Usage: "(agent) Registring kubelet with set of labels", + Value: &AgentConfig.Labels, + } ) func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command { @@ -141,6 +153,8 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command { ResolvConfFlag, ExtraKubeletArgs, ExtraKubeProxyArgs, + NodeLabels, + NodeTaints, }, } } diff --git a/pkg/cli/cmds/server.go b/pkg/cli/cmds/server.go index 27e62f0c20..eb4b715609 100644 --- a/pkg/cli/cmds/server.go +++ b/pkg/cli/cmds/server.go @@ -147,6 +147,8 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command { ResolvConfFlag, ExtraKubeletArgs, ExtraKubeProxyArgs, + NodeLabels, + NodeTaints, }, } } diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index 5011132fe1..50288c4f4d 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -173,6 +173,7 @@ func run(app *cli.Context, cfg *cmds.Server) error { agentConfig.DataDir = filepath.Dir(serverConfig.ControlConfig.DataDir) agentConfig.ServerURL = url agentConfig.Token = token + agentConfig.Labels = append(agentConfig.Labels, "node-role.kubernetes.io/master=true") return agent.Run(ctx, agentConfig) } diff --git a/pkg/daemons/agent/agent.go b/pkg/daemons/agent/agent.go index cfcd4df04a..7702e0e56e 100644 --- a/pkg/daemons/agent/agent.go +++ b/pkg/daemons/agent/agent.go @@ -129,6 +129,10 @@ func kubelet(cfg *config.Agent) { argsMap["feature-gates"] = addFeatureGate(argsMap["feature-gates"], "DevicePlugins=false") } + argsMap["node-labels"] = strings.Join(cfg.NodeLabels, ",") + if len(cfg.NodeTaints) > 0 { + argsMap["register-with-taints"] = strings.Join(cfg.NodeTaints, ",") + } args := config.GetArgsList(argsMap, cfg.ExtraKubeletArgs) command.SetArgs(args) diff --git a/pkg/daemons/config/types.go b/pkg/daemons/config/types.go index 48829ad48e..2bf2ee2b46 100644 --- a/pkg/daemons/config/types.go +++ b/pkg/daemons/config/types.go @@ -55,6 +55,8 @@ type Agent struct { ExtraKubeProxyArgs []string PauseImage string CNIPlugin bool + NodeTaints []string + NodeLabels []string } type Control struct {