Allow multipe DNS servers as comma-seperated argument for --dns

Depending on an exact cluster setup multiple dns may make sense.
Comma-seperated lists of DNS server are quite common as DNS servers
are always plain IPs.
This commit is contained in:
Rene Treffer 2017-01-03 10:28:38 +01:00
parent 582187b6fb
commit 42ff859c27
10 changed files with 51 additions and 20 deletions

View File

@ -166,7 +166,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&s.RegisterNode, "register-node", s.RegisterNode, "Register the node with the apiserver (defaults to true if --api-servers is set)") fs.BoolVar(&s.RegisterNode, "register-node", s.RegisterNode, "Register the node with the apiserver (defaults to true if --api-servers is set)")
fs.StringVar(&s.ClusterDomain, "cluster-domain", s.ClusterDomain, "Domain for this cluster. If set, kubelet will configure all containers to search this domain in addition to the host's search domains") fs.StringVar(&s.ClusterDomain, "cluster-domain", s.ClusterDomain, "Domain for this cluster. If set, kubelet will configure all containers to search this domain in addition to the host's search domains")
fs.StringVar(&s.MasterServiceNamespace, "master-service-namespace", s.MasterServiceNamespace, "The namespace from which the kubernetes master services should be injected into pods") fs.StringVar(&s.MasterServiceNamespace, "master-service-namespace", s.MasterServiceNamespace, "The namespace from which the kubernetes master services should be injected into pods")
fs.StringVar(&s.ClusterDNS, "cluster-dns", s.ClusterDNS, "IP address for a cluster DNS server. This value is used for containers' DNS server in case of Pods with \"dnsPolicy=ClusterFirst\"") fs.StringSliceVar(&s.ClusterDNS, "cluster-dns", s.ClusterDNS, "Comma-separated list of DNS server IP address. This value is used for containers DNS server in case of Pods with \"dnsPolicy=ClusterFirst\". Note: all DNS servers appearing in the list MUST serve the same set of records otherwise name resolution within the cluster may not work correctly. There is no guarantee as to which DNS server may be contacted for name resolution.")
fs.DurationVar(&s.StreamingConnectionIdleTimeout.Duration, "streaming-connection-idle-timeout", s.StreamingConnectionIdleTimeout.Duration, "Maximum time a streaming connection can be idle before the connection is automatically closed. 0 indicates no timeout. Example: '5m'") fs.DurationVar(&s.StreamingConnectionIdleTimeout.Duration, "streaming-connection-idle-timeout", s.StreamingConnectionIdleTimeout.Duration, "Maximum time a streaming connection can be idle before the connection is automatically closed. 0 indicates no timeout. Example: '5m'")
fs.DurationVar(&s.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", s.NodeStatusUpdateFrequency.Duration, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s") fs.DurationVar(&s.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", s.NodeStatusUpdateFrequency.Duration, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s")
s.NodeLabels = make(map[string]string) s.NodeLabels = make(map[string]string)

View File

@ -239,10 +239,10 @@ type KubeletConfiguration struct {
// masterServiceNamespace is The namespace from which the kubernetes // masterServiceNamespace is The namespace from which the kubernetes
// master services should be injected into pods. // master services should be injected into pods.
MasterServiceNamespace string MasterServiceNamespace string
// clusterDNS is the IP address for a cluster DNS server. If set, kubelet // clusterDNS is a list of IP address for a cluster DNS server. If set,
// will configure all containers to use this for DNS resolution in // kubelet will configure all containers to use this for DNS resolution
// addition to the host's DNS servers // instead of the host's DNS servers
ClusterDNS string ClusterDNS []string
// streamingConnectionIdleTimeout is the maximum time a streaming connection // streamingConnectionIdleTimeout is the maximum time a streaming connection
// can be idle before the connection is automatically closed. // can be idle before the connection is automatically closed.
StreamingConnectionIdleTimeout metav1.Duration StreamingConnectionIdleTimeout metav1.Duration

View File

@ -293,10 +293,10 @@ type KubeletConfiguration struct {
// masterServiceNamespace is The namespace from which the kubernetes // masterServiceNamespace is The namespace from which the kubernetes
// master services should be injected into pods. // master services should be injected into pods.
MasterServiceNamespace string `json:"masterServiceNamespace"` MasterServiceNamespace string `json:"masterServiceNamespace"`
// clusterDNS is the IP address for a cluster DNS server. If set, kubelet // clusterDNS is a list of IP address for the cluster DNS server. If set,
// will configure all containers to use this for DNS resolution in // kubelet will configure all containers to use this for DNS resolution
// addition to the host's DNS servers // instead of the host's DNS servers
ClusterDNS string `json:"clusterDNS"` ClusterDNS []string `json:"clusterDNS"`
// streamingConnectionIdleTimeout is the maximum time a streaming connection // streamingConnectionIdleTimeout is the maximum time a streaming connection
// can be idle before the connection is automatically closed. // can be idle before the connection is automatically closed.
StreamingConnectionIdleTimeout metav1.Duration `json:"streamingConnectionIdleTimeout"` StreamingConnectionIdleTimeout metav1.Duration `json:"streamingConnectionIdleTimeout"`

View File

@ -376,7 +376,7 @@ func autoConvert_v1alpha1_KubeletConfiguration_To_componentconfig_KubeletConfigu
} }
out.ClusterDomain = in.ClusterDomain out.ClusterDomain = in.ClusterDomain
out.MasterServiceNamespace = in.MasterServiceNamespace out.MasterServiceNamespace = in.MasterServiceNamespace
out.ClusterDNS = in.ClusterDNS out.ClusterDNS = *(*[]string)(unsafe.Pointer(&in.ClusterDNS))
out.StreamingConnectionIdleTimeout = in.StreamingConnectionIdleTimeout out.StreamingConnectionIdleTimeout = in.StreamingConnectionIdleTimeout
out.NodeStatusUpdateFrequency = in.NodeStatusUpdateFrequency out.NodeStatusUpdateFrequency = in.NodeStatusUpdateFrequency
out.ImageMinimumGCAge = in.ImageMinimumGCAge out.ImageMinimumGCAge = in.ImageMinimumGCAge
@ -548,7 +548,7 @@ func autoConvert_componentconfig_KubeletConfiguration_To_v1alpha1_KubeletConfigu
} }
out.ClusterDomain = in.ClusterDomain out.ClusterDomain = in.ClusterDomain
out.MasterServiceNamespace = in.MasterServiceNamespace out.MasterServiceNamespace = in.MasterServiceNamespace
out.ClusterDNS = in.ClusterDNS out.ClusterDNS = *(*[]string)(unsafe.Pointer(&in.ClusterDNS))
out.StreamingConnectionIdleTimeout = in.StreamingConnectionIdleTimeout out.StreamingConnectionIdleTimeout = in.StreamingConnectionIdleTimeout
out.NodeStatusUpdateFrequency = in.NodeStatusUpdateFrequency out.NodeStatusUpdateFrequency = in.NodeStatusUpdateFrequency
out.ImageMinimumGCAge = in.ImageMinimumGCAge out.ImageMinimumGCAge = in.ImageMinimumGCAge

View File

@ -219,6 +219,11 @@ func DeepCopy_v1alpha1_KubeletConfiguration(in interface{}, out interface{}, c *
*out = new(bool) *out = new(bool)
**out = **in **out = **in
} }
if in.ClusterDNS != nil {
in, out := &in.ClusterDNS, &out.ClusterDNS
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.ImageGCHighThresholdPercent != nil { if in.ImageGCHighThresholdPercent != nil {
in, out := &in.ImageGCHighThresholdPercent, &out.ImageGCHighThresholdPercent in, out := &in.ImageGCHighThresholdPercent, &out.ImageGCHighThresholdPercent
*out = new(int32) *out = new(int32)

View File

@ -193,6 +193,11 @@ func DeepCopy_componentconfig_KubeletConfiguration(in interface{}, out interface
*out = make([]string, len(*in)) *out = make([]string, len(*in))
copy(*out, *in) copy(*out, *in)
} }
if in.ClusterDNS != nil {
in, out := &in.ClusterDNS, &out.ClusterDNS
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.RegisterWithTaints != nil { if in.RegisterWithTaints != nil {
in, out := &in.RegisterWithTaints, &out.RegisterWithTaints in, out := &in.RegisterWithTaints, &out.RegisterWithTaints
*out = make([]api.Taint, len(*in)) *out = make([]api.Taint, len(*in))

View File

@ -10008,11 +10008,18 @@ func GetOpenAPIDefinitions(ref openapi.ReferenceCallback) map[string]openapi.Ope
}, },
"clusterDNS": { "clusterDNS": {
SchemaProps: spec.SchemaProps{ SchemaProps: spec.SchemaProps{
Description: "clusterDNS is the IP address for a cluster DNS server. If set, kubelet will configure all containers to use this for DNS resolution in addition to the host's DNS servers", Description: "clusterDNS is a list of IP address for the cluster DNS server. If set, kubelet will configure all containers to use this for DNS resolution instead of the host's DNS servers",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"string"}, Type: []string{"string"},
Format: "", Format: "",
}, },
}, },
},
},
},
"streamingConnectionIdleTimeout": { "streamingConnectionIdleTimeout": {
SchemaProps: spec.SchemaProps{ SchemaProps: spec.SchemaProps{
Description: "streamingConnectionIdleTimeout is the maximum time a streaming connection can be idle before the connection is automatically closed.", Description: "streamingConnectionIdleTimeout is the maximum time a streaming connection can be idle before the connection is automatically closed.",

View File

@ -422,6 +422,16 @@ func NewMainKubelet(kubeCfg *componentconfig.KubeletConfiguration, kubeDeps *Kub
oomWatcher := NewOOMWatcher(kubeDeps.CAdvisorInterface, kubeDeps.Recorder) oomWatcher := NewOOMWatcher(kubeDeps.CAdvisorInterface, kubeDeps.Recorder)
clusterDNS := make([]net.IP, 0, len(kubeCfg.ClusterDNS))
for _, ipEntry := range kubeCfg.ClusterDNS {
ip := net.ParseIP(ipEntry)
if ip == nil {
glog.Warningf("Invalid clusterDNS ip '%q'", ipEntry)
} else {
clusterDNS = append(clusterDNS, ip)
}
}
klet := &Kubelet{ klet := &Kubelet{
hostname: hostname, hostname: hostname,
nodeName: nodeName, nodeName: nodeName,
@ -436,7 +446,7 @@ func NewMainKubelet(kubeCfg *componentconfig.KubeletConfiguration, kubeDeps *Kub
registerSchedulable: kubeCfg.RegisterSchedulable, registerSchedulable: kubeCfg.RegisterSchedulable,
standaloneMode: standaloneMode, standaloneMode: standaloneMode,
clusterDomain: kubeCfg.ClusterDomain, clusterDomain: kubeCfg.ClusterDomain,
clusterDNS: net.ParseIP(kubeCfg.ClusterDNS), clusterDNS: clusterDNS,
serviceLister: serviceLister, serviceLister: serviceLister,
nodeLister: nodeLister, nodeLister: nodeLister,
nodeInfo: nodeInfo, nodeInfo: nodeInfo,
@ -860,7 +870,7 @@ type Kubelet struct {
clusterDomain string clusterDomain string
// If non-nil, use this for container DNS server. // If non-nil, use this for container DNS server.
clusterDNS net.IP clusterDNS []net.IP
// masterServiceNamespace is the namespace that the master service is exposed in. // masterServiceNamespace is the namespace that the master service is exposed in.
masterServiceNamespace string masterServiceNamespace string
@ -1277,7 +1287,7 @@ func (kl *Kubelet) GetClusterDNS(pod *v1.Pod) ([]string, []string, error) {
} }
} }
useClusterFirstPolicy := pod.Spec.DNSPolicy == v1.DNSClusterFirst useClusterFirstPolicy := pod.Spec.DNSPolicy == v1.DNSClusterFirst
if useClusterFirstPolicy && kl.clusterDNS == nil { if useClusterFirstPolicy && len(kl.clusterDNS) == 0 {
// clusterDNS is not known. // clusterDNS is not known.
// pod with ClusterDNSFirst Policy cannot be created // pod with ClusterDNSFirst Policy cannot be created
kl.recorder.Eventf(pod, v1.EventTypeWarning, "MissingClusterDNS", "kubelet does not have ClusterDNS IP configured and cannot create Pod using %q policy. Falling back to DNSDefault policy.", pod.Spec.DNSPolicy) kl.recorder.Eventf(pod, v1.EventTypeWarning, "MissingClusterDNS", "kubelet does not have ClusterDNS IP configured and cannot create Pod using %q policy. Falling back to DNSDefault policy.", pod.Spec.DNSPolicy)
@ -1308,8 +1318,12 @@ func (kl *Kubelet) GetClusterDNS(pod *v1.Pod) ([]string, []string, error) {
// for a pod with DNSClusterFirst policy, the cluster DNS server is the only nameserver configured for // for a pod with DNSClusterFirst policy, the cluster DNS server is the only nameserver configured for
// the pod. The cluster DNS server itself will forward queries to other nameservers that is configured to use, // the pod. The cluster DNS server itself will forward queries to other nameservers that is configured to use,
// in case the cluster DNS server cannot resolve the DNS query itself // in case the cluster DNS server cannot resolve the DNS query itself
dns := []string{kl.clusterDNS.String()} dns := make([]string, len(kl.clusterDNS))
for i, ip := range kl.clusterDNS {
dns[i] = ip.String()
}
dnsSearch := kl.formDNSSearch(hostSearch, pod) dnsSearch := kl.formDNSSearch(hostSearch, pod)
return dns, dnsSearch, nil return dns, dnsSearch, nil
} }

View File

@ -174,7 +174,7 @@ func TestGenerateRunContainerOptions_DNSConfigurationParams(t *testing.T) {
clusterNS := "203.0.113.1" clusterNS := "203.0.113.1"
kubelet.clusterDomain = "kubernetes.io" kubelet.clusterDomain = "kubernetes.io"
kubelet.clusterDNS = net.ParseIP(clusterNS) kubelet.clusterDNS = []net.IP{net.ParseIP(clusterNS)}
pods := newTestPods(2) pods := newTestPods(2)
pods[0].Spec.DNSPolicy = v1.DNSClusterFirst pods[0].Spec.DNSPolicy = v1.DNSClusterFirst

View File

@ -128,7 +128,7 @@ func GetHollowKubeletConfig(
c.EvictionPressureTransitionPeriod.Duration = 5 * time.Minute c.EvictionPressureTransitionPeriod.Duration = 5 * time.Minute
c.MaxPods = int32(maxPods) c.MaxPods = int32(maxPods)
c.PodsPerCore = int32(podsPerCore) c.PodsPerCore = int32(podsPerCore)
c.ClusterDNS = "" c.ClusterDNS = []string{}
c.DockerExecHandlerName = "native" c.DockerExecHandlerName = "native"
c.ImageGCHighThresholdPercent = 90 c.ImageGCHighThresholdPercent = 90
c.ImageGCLowThresholdPercent = 80 c.ImageGCLowThresholdPercent = 80