Merge pull request #454 from galal-hussein/node_labels_taints

Expose node labels and taints and add node roles
pull/498/head
Darren Shepherd 2019-05-25 00:39:55 +02:00 committed by GitHub
commit 4b4dd1b59b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 35 additions and 0 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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())

View File

@ -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,
},
}
}

View File

@ -147,6 +147,8 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
ResolvConfFlag,
ExtraKubeletArgs,
ExtraKubeProxyArgs,
NodeLabels,
NodeTaints,
},
}
}

View File

@ -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)
}

View File

@ -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)

View File

@ -55,6 +55,8 @@ type Agent struct {
ExtraKubeProxyArgs []string
PauseImage string
CNIPlugin bool
NodeTaints []string
NodeLabels []string
}
type Control struct {