diff --git a/cmd/kubeadm/app/master/addons.go b/cmd/kubeadm/app/master/addons.go index 90d60e03e91..1f29d152fc6 100644 --- a/cmd/kubeadm/app/master/addons.go +++ b/cmd/kubeadm/app/master/addons.go @@ -20,7 +20,6 @@ import ( "fmt" "net" "path" - "runtime" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" "k8s.io/kubernetes/cmd/kubeadm/app/images" @@ -31,15 +30,11 @@ import ( "k8s.io/kubernetes/pkg/util/intstr" ) -// TODO(phase1+): kube-proxy should be a daemonset, three different daemonsets should not be here -func createKubeProxyPodSpec(cfg *kubeadmapi.MasterConfiguration, architecture string) api.PodSpec { +func createKubeProxyPodSpec(cfg *kubeadmapi.MasterConfiguration) api.PodSpec { envParams := kubeadmapi.GetEnvParams() privilegedTrue := true return api.PodSpec{ SecurityContext: &api.PodSecurityContext{HostNetwork: true}, - NodeSelector: map[string]string{ - "beta.kubernetes.io/arch": architecture, - }, Containers: []api.Container{{ Name: kubeProxy, Image: images.GetCoreImage(images.KubeProxyImage, cfg, envParams["hyperkube_image"]), @@ -108,9 +103,6 @@ func createKubeDNSPodSpec(cfg *kubeadmapi.MasterConfiguration) api.PodSpec { ) return api.PodSpec{ - NodeSelector: map[string]string{ - "beta.kubernetes.io/arch": runtime.GOARCH, - }, Containers: []api.Container{ // DNS server { @@ -237,21 +229,19 @@ func createKubeDNSServiceSpec(cfg *kubeadmapi.MasterConfiguration) (*api.Service } func CreateEssentialAddons(cfg *kubeadmapi.MasterConfiguration, client *clientset.Clientset) error { - arches := [3]string{"amd64", "arm", "arm64"} + kubeProxyDaemonSet := NewDaemonSet(kubeProxy, createKubeProxyPodSpec(cfg)) + SetMasterTaintTolerations(&kubeProxyDaemonSet.Spec.Template.ObjectMeta) + SetNodeAffinity(&kubeProxyDaemonSet.Spec.Template.ObjectMeta, NativeArchitectureNodeAffinity()) - for _, arch := range arches { - kubeProxyDaemonSet := NewDaemonSet(kubeProxy+"-"+arch, createKubeProxyPodSpec(cfg, arch)) - SetMasterTaintTolerations(&kubeProxyDaemonSet.Spec.Template.ObjectMeta) - - if _, err := client.Extensions().DaemonSets(api.NamespaceSystem).Create(kubeProxyDaemonSet); err != nil { - return fmt.Errorf(" failed creating essential kube-proxy addon [%v]", err) - } + if _, err := client.Extensions().DaemonSets(api.NamespaceSystem).Create(kubeProxyDaemonSet); err != nil { + return fmt.Errorf(" failed creating essential kube-proxy addon [%v]", err) } fmt.Println(" created essential addon: kube-proxy") kubeDNSDeployment := NewDeployment("kube-dns", 1, createKubeDNSPodSpec(cfg)) SetMasterTaintTolerations(&kubeDNSDeployment.Spec.Template.ObjectMeta) + SetNodeAffinity(&kubeDNSDeployment.Spec.Template.ObjectMeta, NativeArchitectureNodeAffinity()) if _, err := client.Extensions().Deployments(api.NamespaceSystem).Create(kubeDNSDeployment); err != nil { return fmt.Errorf(" failed creating essential kube-dns addon [%v]", err) diff --git a/cmd/kubeadm/app/master/apiclient.go b/cmd/kubeadm/app/master/apiclient.go index 5a68cec3796..c75fe2f8585 100644 --- a/cmd/kubeadm/app/master/apiclient.go +++ b/cmd/kubeadm/app/master/apiclient.go @@ -19,6 +19,7 @@ package master import ( "encoding/json" "fmt" + "runtime" "time" "k8s.io/kubernetes/cmd/kubeadm/app/images" @@ -206,14 +207,11 @@ func SetMasterTaintTolerations(meta *api.ObjectMeta) { meta.Annotations[api.TolerationsAnnotationKey] = string(tolerationsAnnotation) } -func SetMasterNodeAffinity(meta *api.ObjectMeta) { +// SetNodeAffinity is a basic helper to set meta.Annotations[api.AffinityAnnotationKey] for one or more api.NodeSelectorRequirement(s) +func SetNodeAffinity(meta *api.ObjectMeta, expr ...api.NodeSelectorRequirement) { nodeAffinity := &api.NodeAffinity{ RequiredDuringSchedulingIgnoredDuringExecution: &api.NodeSelector{ - NodeSelectorTerms: []api.NodeSelectorTerm{{ - MatchExpressions: []api.NodeSelectorRequirement{{ - Key: "kubeadm.alpha.kubernetes.io/role", Operator: api.NodeSelectorOpIn, Values: []string{"master"}, - }}, - }}, + NodeSelectorTerms: []api.NodeSelectorTerm{{MatchExpressions: expr}}, }, } affinityAnnotation, _ := json.Marshal(api.Affinity{NodeAffinity: nodeAffinity}) @@ -223,6 +221,21 @@ func SetMasterNodeAffinity(meta *api.ObjectMeta) { meta.Annotations[api.AffinityAnnotationKey] = string(affinityAnnotation) } +// MasterNodeAffinity returns api.NodeSelectorRequirement to be used with SetNodeAffinity to set affinity to master node +func MasterNodeAffinity() api.NodeSelectorRequirement { + return api.NodeSelectorRequirement{ + Key: "kubeadm.alpha.kubernetes.io/role", Operator: api.NodeSelectorOpIn, Values: []string{"master"}, + } +} + +// NativeArchitectureNodeAffinity returns api.NodeSelectorRequirement to be used with SetNodeAffinity to nodes with CPU architecture +// the same as master node +func NativeArchitectureNodeAffinity() api.NodeSelectorRequirement { + return api.NodeSelectorRequirement{ + Key: "beta.kubernetes.io/arch", Operator: api.NodeSelectorOpIn, Values: []string{runtime.GOARCH}, + } +} + func createDummyDeployment(client *clientset.Clientset) { fmt.Println(" attempting a test deployment") dummyDeployment := NewDeployment("dummy", 1, api.PodSpec{ diff --git a/cmd/kubeadm/app/master/discovery.go b/cmd/kubeadm/app/master/discovery.go index 0959d9d5a95..c261ddabcad 100644 --- a/cmd/kubeadm/app/master/discovery.go +++ b/cmd/kubeadm/app/master/discovery.go @@ -112,7 +112,7 @@ func newKubeDiscovery(cfg *kubeadmapi.MasterConfiguration, caCert *x509.Certific } SetMasterTaintTolerations(&kd.Deployment.Spec.Template.ObjectMeta) - SetMasterNodeAffinity(&kd.Deployment.Spec.Template.ObjectMeta) + SetNodeAffinity(&kd.Deployment.Spec.Template.ObjectMeta, MasterNodeAffinity(), NativeArchitectureNodeAffinity()) return kd }