Skip to content

Commit

Permalink
Merge pull request #9491 from johngmyers/nodeport-dns
Browse files Browse the repository at this point in the history
Default ClusterDNS appropriately when NodeLocalDNS is enabled
  • Loading branch information
k8s-ci-robot committed Jul 6, 2020
2 parents 61cb11b + 004f7b5 commit a97fc42
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
12 changes: 1 addition & 11 deletions docs/cluster_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ spec:

## Node local DNS cache

As of kops 1.18, you can enable NodeLocal DNSCache if you are using CoreDNS. It is used to improve improve the Cluster DNS performance by running a dns caching agent on cluster nodes as a DaemonSet.
As of kops 1.18, you can enable NodeLocal DNSCache if you are using CoreDNS. It is used to improve the Cluster DNS performance by running a dns caching agent on cluster nodes as a DaemonSet.

```yaml
spec:
Expand All @@ -593,16 +593,6 @@ spec:
enabled: true
```

If you are using kube-proxy in ipvs mode or Cilium as CNI, you have to set the nodeLocalDNS as ClusterDNS.

```yaml
spec:
kubelet:
clusterDNS: 169.254.20.10
masterKubelet:
clusterDNS: 169.254.20.10
```

## kubeControllerManager
This block contains configurations for the `controller-manager`.

Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/kops/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,11 @@ func validateNodeLocalDNS(spec *kops.ClusterSpec, fldpath *field.Path) field.Err
}

if (spec.KubeProxy != nil && spec.KubeProxy.ProxyMode == "ipvs") || (spec.Networking != nil && spec.Networking.Cilium != nil) {
if spec.Kubelet != nil && spec.Kubelet.ClusterDNS != spec.KubeDNS.NodeLocalDNS.LocalIP {
if spec.Kubelet != nil && spec.Kubelet.ClusterDNS != "" && spec.Kubelet.ClusterDNS != spec.KubeDNS.NodeLocalDNS.LocalIP {
allErrs = append(allErrs, field.Forbidden(fldpath.Child("kubelet", "clusterDNS"), "Kubelet ClusterDNS must be set to the default IP address for LocalIP"))
}

if spec.MasterKubelet != nil && spec.MasterKubelet.ClusterDNS != spec.KubeDNS.NodeLocalDNS.LocalIP {
if spec.MasterKubelet != nil && spec.MasterKubelet.ClusterDNS != "" && spec.MasterKubelet.ClusterDNS != spec.KubeDNS.NodeLocalDNS.LocalIP {
allErrs = append(allErrs, field.Forbidden(fldpath.Child("kubelet", "clusterDNS"), "MasterKubelet ClusterDNS must be set to the default IP address for LocalIP"))
}
}
Expand Down
13 changes: 9 additions & 4 deletions pkg/model/components/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ func (b *KubeletOptionsBuilder) BuildOptions(o interface{}) error {
}

if clusterSpec.Kubelet.ClusterDNS == "" {
ip, err := WellKnownServiceIP(clusterSpec, 10)
if err != nil {
return err
if clusterSpec.KubeDNS != nil && clusterSpec.KubeDNS.NodeLocalDNS != nil && fi.BoolValue(clusterSpec.KubeDNS.NodeLocalDNS.Enabled) &&
((clusterSpec.KubeProxy != nil && clusterSpec.KubeProxy.ProxyMode == "ipvs") || (clusterSpec.Networking != nil && clusterSpec.Networking.Cilium != nil)) {
clusterSpec.Kubelet.ClusterDNS = clusterSpec.KubeDNS.NodeLocalDNS.LocalIP
} else {
ip, err := WellKnownServiceIP(clusterSpec, 10)
if err != nil {
return err
}
clusterSpec.Kubelet.ClusterDNS = ip.String()
}
clusterSpec.Kubelet.ClusterDNS = ip.String()
}

clusterSpec.MasterKubelet.RegisterSchedulable = fi.Bool(false)
Expand Down

0 comments on commit a97fc42

Please sign in to comment.