Skip to content

Commit ca88477

Browse files
authored
Merge pull request #2088 from brb/no-kube-proxy
Add possibility to disable kube-proxy
2 parents e721c4a + abf42e2 commit ca88477

File tree

9 files changed

+35
-18
lines changed

9 files changed

+35
-18
lines changed

pkg/apis/config/v1alpha4/default.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func SetDefaultsCluster(obj *Cluster) {
6868
}
6969
// default the KubeProxyMode using iptables as it's already the default
7070
if obj.Networking.KubeProxyMode == "" {
71-
obj.Networking.KubeProxyMode = IPTablesMode
71+
obj.Networking.KubeProxyMode = IPTablesProxyMode
7272
}
7373
}
7474

pkg/apis/config/v1alpha4/types.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ const (
202202
type ProxyMode string
203203

204204
const (
205-
// IPTablesMode sets ProxyMode to iptables
206-
IPTablesMode ProxyMode = "iptables"
207-
// IPVSMode sets ProxyMode to iptables
208-
IPVSMode ProxyMode = "ipvs"
205+
// IPTablesProxyMode sets ProxyMode to iptables
206+
IPTablesProxyMode ProxyMode = "iptables"
207+
// IPVSProxyMode sets ProxyMode to iptables
208+
IPVSProxyMode ProxyMode = "ipvs"
209209
)
210210

211211
// PatchJSON6902 represents an inline kustomize json 6902 patch

pkg/cluster/internal/create/actions/kubeadminit/init.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ import (
2626
"sigs.k8s.io/kind/pkg/cluster/nodeutils"
2727

2828
"sigs.k8s.io/kind/pkg/cluster/internal/create/actions"
29+
"sigs.k8s.io/kind/pkg/internal/apis/config"
2930
)
3031

3132
// kubeadmInitAction implements action for executing the kubeadm init
3233
// and a set of default post init operations like e.g. install the
3334
// CNI network plugin.
34-
type action struct{}
35+
type action struct {
36+
skipKubeProxy bool
37+
}
3538

3639
// NewAction returns a new action for kubeadm init
37-
func NewAction() actions.Action {
38-
return &action{}
40+
func NewAction(cfg *config.Cluster) actions.Action {
41+
return &action{skipKubeProxy: cfg.Networking.KubeProxyMode == config.NoneProxyMode}
3942
}
4043

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

62+
// skip preflight checks, as these have undesirable side effects
63+
// and don't tell us much. requires kubeadm 1.13+
64+
skipPhases := "preflight"
65+
if a.skipKubeProxy {
66+
skipPhases += ",addon/kube-proxy"
67+
}
68+
5969
// run kubeadm
6070
cmd := node.Command(
6171
// init because this is the control plane node
6272
"kubeadm", "init",
63-
// skip preflight checks, as these have undesirable side effects
64-
// and don't tell us much. requires kubeadm 1.13+
65-
"--skip-phases=preflight",
73+
"--skip-phases="+skipPhases,
6674
// specify our generated config file
6775
"--config=/kind/kubeadm.conf",
6876
"--skip-token-print",

pkg/cluster/internal/create/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func Cluster(logger log.Logger, p providers.Provider, opts *ClusterOptions) erro
108108
}
109109
if !opts.StopBeforeSettingUpKubernetes {
110110
actionsToRun = append(actionsToRun,
111-
kubeadminit.NewAction(), // run kubeadm init
111+
kubeadminit.NewAction(opts.Config), // run kubeadm init
112112
)
113113
// this step might be skipped, but is next after init
114114
if !opts.Config.Networking.DisableDefaultCNI {

pkg/cluster/internal/kubeadm/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ evictionHard:
245245
{{ range $key := .SortedFeatureGateKeys }}
246246
"{{ $key }}": {{$.FeatureGates $key }}
247247
{{end}}{{end}}
248+
{{if ne .KubeProxyMode "None"}}
248249
---
249250
apiVersion: kubeproxy.config.k8s.io/v1alpha1
250251
kind: KubeProxyConfiguration
@@ -257,6 +258,7 @@ mode: "{{ .KubeProxyMode }}"
257258
{{end}}{{end}}
258259
iptables:
259260
minSyncPeriod: 1s
261+
{{end}}
260262
`
261263

262264
// ConfigTemplateBetaV2 is the kubeadm config template for API version v1beta2
@@ -370,6 +372,7 @@ evictionHard:
370372
{{ range $key := .SortedFeatureGateKeys }}
371373
"{{ $key }}": {{ index $.FeatureGates $key }}
372374
{{end}}{{end}}
375+
{{if ne .KubeProxyMode "None"}}
373376
---
374377
apiVersion: kubeproxy.config.k8s.io/v1alpha1
375378
kind: KubeProxyConfiguration
@@ -382,6 +385,7 @@ mode: "{{ .KubeProxyMode }}"
382385
{{end}}{{end}}
383386
iptables:
384387
minSyncPeriod: 1s
388+
{{end}}
385389
`
386390

387391
// Config returns a kubeadm config generated from config data, in particular

pkg/internal/apis/config/default.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/internal/apis/config/types.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,12 @@ const (
163163
type ProxyMode string
164164

165165
const (
166-
// IPTablesMode sets ProxyMode to iptables
167-
IPTablesMode ProxyMode = "iptables"
168-
// IPVSMode sets ProxyMode to iptables
169-
IPVSMode ProxyMode = "ipvs"
166+
// IPTablesProxyMode sets ProxyMode to iptables
167+
IPTablesProxyMode ProxyMode = "iptables"
168+
// IPVSProxyMode sets ProxyMode to iptables
169+
IPVSProxyMode ProxyMode = "ipvs"
170+
// NoneProxyMode disables kube-proxy
171+
NoneProxyMode ProxyMode = "none"
170172
)
171173

172174
// PatchJSON6902 represents an inline kustomize json 6902 patch

pkg/internal/apis/config/validate.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func (c *Cluster) Validate() error {
5959
}
6060

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

site/content/docs/user/configuration.md

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ networking:
168168
kubeProxyMode: "ipvs"
169169
{{< /codeFromInline >}}
170170

171+
To disable kube-proxy, set the mode to `"none"`.
172+
171173
### Nodes
172174
The `kind: Cluster` object has a `nodes` field containing a list of `node`
173175
objects. If unset this defaults to:

0 commit comments

Comments
 (0)