Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to disable kube-proxy #2088

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apis/config/v1alpha4/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func SetDefaultsCluster(obj *Cluster) {
}
// default the KubeProxyMode using iptables as it's already the default
if obj.Networking.KubeProxyMode == "" {
obj.Networking.KubeProxyMode = IPTablesMode
obj.Networking.KubeProxyMode = IPTablesProxyMode
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/config/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ const (
type ProxyMode string

const (
// IPTablesMode sets ProxyMode to iptables
IPTablesMode ProxyMode = "iptables"
// IPVSMode sets ProxyMode to iptables
IPVSMode ProxyMode = "ipvs"
// IPTablesProxyMode sets ProxyMode to iptables
IPTablesProxyMode ProxyMode = "iptables"
// IPVSProxyMode sets ProxyMode to iptables
IPVSProxyMode ProxyMode = "ipvs"
)

// PatchJSON6902 represents an inline kustomize json 6902 patch
Expand Down
20 changes: 14 additions & 6 deletions pkg/cluster/internal/create/actions/kubeadminit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ import (
"sigs.k8s.io/kind/pkg/cluster/nodeutils"

"sigs.k8s.io/kind/pkg/cluster/internal/create/actions"
"sigs.k8s.io/kind/pkg/internal/apis/config"
)

// kubeadmInitAction implements action for executing the kubeadm init
// and a set of default post init operations like e.g. install the
// CNI network plugin.
type action struct{}
type action struct {
skipKubeProxy bool
}

// NewAction returns a new action for kubeadm init
func NewAction() actions.Action {
return &action{}
func NewAction(cfg *config.Cluster) actions.Action {
return &action{skipKubeProxy: cfg.Networking.KubeProxyMode == config.NoneProxyMode}
}

// Execute runs the action
Expand All @@ -56,13 +59,18 @@ func (a *action) Execute(ctx *actions.ActionContext) error {
return err
}

// skip preflight checks, as these have undesirable side effects
// and don't tell us much. requires kubeadm 1.13+
skipPhases := "preflight"
if a.skipKubeProxy {
skipPhases += ",addon/kube-proxy"
}

// run kubeadm
cmd := node.Command(
// init because this is the control plane node
"kubeadm", "init",
// skip preflight checks, as these have undesirable side effects
// and don't tell us much. requires kubeadm 1.13+
"--skip-phases=preflight",
"--skip-phases="+skipPhases,
// specify our generated config file
"--config=/kind/kubeadm.conf",
"--skip-token-print",
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/internal/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func Cluster(logger log.Logger, p providers.Provider, opts *ClusterOptions) erro
}
if !opts.StopBeforeSettingUpKubernetes {
actionsToRun = append(actionsToRun,
kubeadminit.NewAction(), // run kubeadm init
kubeadminit.NewAction(opts.Config), // run kubeadm init
)
// this step might be skipped, but is next after init
if !opts.Config.Networking.DisableDefaultCNI {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cluster/internal/kubeadm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ evictionHard:
{{ range $key := .SortedFeatureGateKeys }}
"{{ $key }}": {{$.FeatureGates $key }}
{{end}}{{end}}
{{if ne .KubeProxyMode "None"}}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
Expand All @@ -252,6 +253,7 @@ mode: "{{ .KubeProxyMode }}"
{{end}}{{end}}
iptables:
minSyncPeriod: 1s
{{end}}
`

// ConfigTemplateBetaV2 is the kubeadm config template for API version v1beta2
Expand Down Expand Up @@ -360,6 +362,7 @@ evictionHard:
{{ range $key := .SortedFeatureGateKeys }}
"{{ $key }}": {{ index $.FeatureGates $key }}
{{end}}{{end}}
{{if ne .KubeProxyMode "None"}}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
Expand All @@ -372,6 +375,7 @@ mode: "{{ .KubeProxyMode }}"
{{end}}{{end}}
iptables:
minSyncPeriod: 1s
{{end}}
`

// Config returns a kubeadm config generated from config data, in particular
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/apis/config/default.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions pkg/internal/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ const (
type ProxyMode string

const (
// IPTablesMode sets ProxyMode to iptables
IPTablesMode ProxyMode = "iptables"
// IPVSMode sets ProxyMode to iptables
IPVSMode ProxyMode = "ipvs"
// IPTablesProxyMode sets ProxyMode to iptables
IPTablesProxyMode ProxyMode = "iptables"
// IPVSProxyMode sets ProxyMode to iptables
IPVSProxyMode ProxyMode = "ipvs"
// NoneProxyMode disables kube-proxy
NoneProxyMode ProxyMode = "none"
)

// PatchJSON6902 represents an inline kustomize json 6902 patch
Expand Down
3 changes: 2 additions & 1 deletion pkg/internal/apis/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func (c *Cluster) Validate() error {
}

// KubeProxyMode should be iptables or ipvs
if c.Networking.KubeProxyMode != IPTablesMode && c.Networking.KubeProxyMode != IPVSMode {
if c.Networking.KubeProxyMode != IPTablesProxyMode && c.Networking.KubeProxyMode != IPVSProxyMode &&
c.Networking.KubeProxyMode != NoneProxyMode {
errs = append(errs, errors.Errorf("invalid kubeProxyMode: %s", c.Networking.KubeProxyMode))
}

Expand Down
4 changes: 3 additions & 1 deletion site/content/docs/user/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ networking:
kubeProxyMode: "ipvs"
{{< /codeFromInline >}}

To disable kube-proxy, set the mode to `"none"`.

### Nodes
The `kind: Cluster` object has a `nodes` field containing a list of `node`
objects. If unset this defaults to:
Expand Down Expand Up @@ -356,4 +358,4 @@ nodes:
{{< /codeFromInline >}}

[YAML]: https://yaml.org/
[feature gates]: https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/
[feature gates]: https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/