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

autodetect advertises address with IPv6 #1195

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions pkg/cluster/internal/create/actions/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func getKubeadmConfig(cfg *config.Cluster, data kubeadm.ConfigData, node nodes.N
return "", errors.Wrap(err, "failed to get IP for node")
}

// TODO: this is no longer needed since v1.18
data.NodeAddress = nodeAddress
// configure the right protocol addresses
if cfg.Networking.IPFamily == "ipv6" {
Expand Down
111 changes: 110 additions & 1 deletion pkg/cluster/internal/kubeadm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,113 @@ metadata:
{{end}}{{end}}
`

// ConfigTemplateV118BetaV2 is the kubadm config template for API version v1beta2 and k8s > v1.18
const ConfigTemplateV118BetaV2 = `# config generated by kind
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
metadata:
name: config
kubernetesVersion: {{.KubernetesVersion}}
clusterName: "{{.ClusterName}}"
controlPlaneEndpoint: "{{ .ControlPlaneEndpoint }}"
# on docker for mac we have to expose the api server via port forward,
# so we need to ensure the cert is valid for localhost so we can talk
# to the cluster after rewriting the kubeconfig to point to localhost
apiServer:
certSANs: [localhost, "{{.APIServerAddress}}"]
extraArgs:
{{ if .IPv6 -}}
bind-address: "::"
{{- end }}
controllerManager:
extraArgs:
enable-hostpath-provisioner: "true"
# configure ipv6 default addresses for IPv6 clusters
{{ if .IPv6 -}}
bind-address: "::1"
{{- end }}
scheduler:
extraArgs:
# configure ipv6 default addresses for IPv6 clusters
{{ if .IPv6 -}}
bind-address: "::1"
{{- end }}
networking:
podSubnet: "{{ .PodSubnet }}"
serviceSubnet: "{{ .ServiceSubnet }}"
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
metadata:
name: config
# we use a well know token for TLS bootstrap
bootstrapTokens:
- token: "{{ .Token }}"
# we use a well know port for making the API server discoverable inside docker network.
# from the host machine such port will be accessible via a random local port instead.
localAPIEndpoint:
{{ if .IPv6 -}}
advertiseAddress: "::"
{{- end }}
bindPort: {{.APIBindPort}}
nodeRegistration:
criSocket: "/run/containerd/containerd.sock"
kubeletExtraArgs:
fail-swap-on: "false"
{{ if .IPv6 -}}
node-ip: "::"
{{- end }}
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: JoinConfiguration
metadata:
name: config
{{ if .ControlPlane -}}
controlPlane:
localAPIEndpoint:
{{ if .IPv6 -}}
advertiseAddress: "::"
{{- end }}
bindPort: {{.APIBindPort}}
{{- end }}
nodeRegistration:
criSocket: "/run/containerd/containerd.sock"
kubeletExtraArgs:
fail-swap-on: "false"
{{ if .IPv6 -}}
node-ip: "::"
{{- end }}
discovery:
bootstrapToken:
apiServerEndpoint: "{{ .ControlPlaneEndpoint }}"
token: "{{ .Token }}"
unsafeSkipCAVerification: true
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
metadata:
name: config
# configure ipv6 addresses in IPv6 mode
{{ if .IPv6 -}}
address: "::"
healthzBindAddress: "::"
{{- end }}
# disable disk resource management by default
# kubelet will see the host disk that the inner container runtime
# is ultimately backed by and attempt to recover disk space. we don't want that.
imageGCHighThresholdPercent: 100
evictionHard:
nodefs.available: "0%"
nodefs.inodesFree: "0%"
imagefs.available: "0%"
---
# no-op entry that exists solely so it can be patched
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
metadata:
name: config
`

// Config returns a kubeadm config generated from config data, in particular
// the kubernetes version
func Config(data ConfigData) (config string, err error) {
Expand All @@ -518,7 +625,7 @@ func Config(data ConfigData) (config string, err error) {
}

// assume the latest API version, then fallback if the k8s version is too low
templateSource := ConfigTemplateBetaV2
templateSource := ConfigTemplateV118BetaV2
if ver.LessThan(version.MustParseSemantic("v1.12.0")) {
// in Kubernetes 1.11 we need to enable this feature, unless the user
// explicitly disabled it. this is considered part of our "base config"
Expand All @@ -532,6 +639,8 @@ func Config(data ConfigData) (config string, err error) {
templateSource = ConfigTemplateAlphaV3
} else if ver.LessThan(version.MustParseSemantic("v1.15.0")) {
templateSource = ConfigTemplateBetaV1
} else if ver.LessThan(version.MustParseSemantic("v1.18.0")) {
templateSource = ConfigTemplateBetaV2
}

t, err := template.New("kubeadm-config").Parse(templateSource)
Expand Down