mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
Eliminate half-baked multi-architecture support, but keep node affinity architecture-agnostic (fix #33916)
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
|
||||||
|
|
||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/images"
|
"k8s.io/kubernetes/cmd/kubeadm/app/images"
|
||||||
@@ -31,15 +30,11 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/util/intstr"
|
"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) api.PodSpec {
|
||||||
func createKubeProxyPodSpec(cfg *kubeadmapi.MasterConfiguration, architecture string) api.PodSpec {
|
|
||||||
envParams := kubeadmapi.GetEnvParams()
|
envParams := kubeadmapi.GetEnvParams()
|
||||||
privilegedTrue := true
|
privilegedTrue := true
|
||||||
return api.PodSpec{
|
return api.PodSpec{
|
||||||
SecurityContext: &api.PodSecurityContext{HostNetwork: true},
|
SecurityContext: &api.PodSecurityContext{HostNetwork: true},
|
||||||
NodeSelector: map[string]string{
|
|
||||||
"beta.kubernetes.io/arch": architecture,
|
|
||||||
},
|
|
||||||
Containers: []api.Container{{
|
Containers: []api.Container{{
|
||||||
Name: kubeProxy,
|
Name: kubeProxy,
|
||||||
Image: images.GetCoreImage(images.KubeProxyImage, cfg, envParams["hyperkube_image"]),
|
Image: images.GetCoreImage(images.KubeProxyImage, cfg, envParams["hyperkube_image"]),
|
||||||
@@ -108,9 +103,6 @@ func createKubeDNSPodSpec(cfg *kubeadmapi.MasterConfiguration) api.PodSpec {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return api.PodSpec{
|
return api.PodSpec{
|
||||||
NodeSelector: map[string]string{
|
|
||||||
"beta.kubernetes.io/arch": runtime.GOARCH,
|
|
||||||
},
|
|
||||||
Containers: []api.Container{
|
Containers: []api.Container{
|
||||||
// DNS server
|
// DNS server
|
||||||
{
|
{
|
||||||
@@ -237,21 +229,19 @@ func createKubeDNSServiceSpec(cfg *kubeadmapi.MasterConfiguration) (*api.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateEssentialAddons(cfg *kubeadmapi.MasterConfiguration, client *clientset.Clientset) error {
|
func CreateEssentialAddons(cfg *kubeadmapi.MasterConfiguration, client *clientset.Clientset) error {
|
||||||
arches := [3]string{"amd64", "arm", "arm64"}
|
kubeProxyDaemonSet := NewDaemonSet(kubeProxy, createKubeProxyPodSpec(cfg))
|
||||||
|
|
||||||
for _, arch := range arches {
|
|
||||||
kubeProxyDaemonSet := NewDaemonSet(kubeProxy+"-"+arch, createKubeProxyPodSpec(cfg, arch))
|
|
||||||
SetMasterTaintTolerations(&kubeProxyDaemonSet.Spec.Template.ObjectMeta)
|
SetMasterTaintTolerations(&kubeProxyDaemonSet.Spec.Template.ObjectMeta)
|
||||||
|
SetNodeAffinity(&kubeProxyDaemonSet.Spec.Template.ObjectMeta, NativeArchitectureNodeAffinity())
|
||||||
|
|
||||||
if _, err := client.Extensions().DaemonSets(api.NamespaceSystem).Create(kubeProxyDaemonSet); err != nil {
|
if _, err := client.Extensions().DaemonSets(api.NamespaceSystem).Create(kubeProxyDaemonSet); err != nil {
|
||||||
return fmt.Errorf("<master/addons> failed creating essential kube-proxy addon [%v]", err)
|
return fmt.Errorf("<master/addons> failed creating essential kube-proxy addon [%v]", err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("<master/addons> created essential addon: kube-proxy")
|
fmt.Println("<master/addons> created essential addon: kube-proxy")
|
||||||
|
|
||||||
kubeDNSDeployment := NewDeployment("kube-dns", 1, createKubeDNSPodSpec(cfg))
|
kubeDNSDeployment := NewDeployment("kube-dns", 1, createKubeDNSPodSpec(cfg))
|
||||||
SetMasterTaintTolerations(&kubeDNSDeployment.Spec.Template.ObjectMeta)
|
SetMasterTaintTolerations(&kubeDNSDeployment.Spec.Template.ObjectMeta)
|
||||||
|
SetNodeAffinity(&kubeDNSDeployment.Spec.Template.ObjectMeta, NativeArchitectureNodeAffinity())
|
||||||
|
|
||||||
if _, err := client.Extensions().Deployments(api.NamespaceSystem).Create(kubeDNSDeployment); err != nil {
|
if _, err := client.Extensions().Deployments(api.NamespaceSystem).Create(kubeDNSDeployment); err != nil {
|
||||||
return fmt.Errorf("<master/addons> failed creating essential kube-dns addon [%v]", err)
|
return fmt.Errorf("<master/addons> failed creating essential kube-dns addon [%v]", err)
|
||||||
|
@@ -19,6 +19,7 @@ package master
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/images"
|
"k8s.io/kubernetes/cmd/kubeadm/app/images"
|
||||||
@@ -206,14 +207,11 @@ func SetMasterTaintTolerations(meta *api.ObjectMeta) {
|
|||||||
meta.Annotations[api.TolerationsAnnotationKey] = string(tolerationsAnnotation)
|
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{
|
nodeAffinity := &api.NodeAffinity{
|
||||||
RequiredDuringSchedulingIgnoredDuringExecution: &api.NodeSelector{
|
RequiredDuringSchedulingIgnoredDuringExecution: &api.NodeSelector{
|
||||||
NodeSelectorTerms: []api.NodeSelectorTerm{{
|
NodeSelectorTerms: []api.NodeSelectorTerm{{MatchExpressions: expr}},
|
||||||
MatchExpressions: []api.NodeSelectorRequirement{{
|
|
||||||
Key: "kubeadm.alpha.kubernetes.io/role", Operator: api.NodeSelectorOpIn, Values: []string{"master"},
|
|
||||||
}},
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
affinityAnnotation, _ := json.Marshal(api.Affinity{NodeAffinity: nodeAffinity})
|
affinityAnnotation, _ := json.Marshal(api.Affinity{NodeAffinity: nodeAffinity})
|
||||||
@@ -223,6 +221,21 @@ func SetMasterNodeAffinity(meta *api.ObjectMeta) {
|
|||||||
meta.Annotations[api.AffinityAnnotationKey] = string(affinityAnnotation)
|
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) {
|
func createDummyDeployment(client *clientset.Clientset) {
|
||||||
fmt.Println("<master/apiclient> attempting a test deployment")
|
fmt.Println("<master/apiclient> attempting a test deployment")
|
||||||
dummyDeployment := NewDeployment("dummy", 1, api.PodSpec{
|
dummyDeployment := NewDeployment("dummy", 1, api.PodSpec{
|
||||||
|
@@ -112,7 +112,7 @@ func newKubeDiscovery(cfg *kubeadmapi.MasterConfiguration, caCert *x509.Certific
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetMasterTaintTolerations(&kd.Deployment.Spec.Template.ObjectMeta)
|
SetMasterTaintTolerations(&kd.Deployment.Spec.Template.ObjectMeta)
|
||||||
SetMasterNodeAffinity(&kd.Deployment.Spec.Template.ObjectMeta)
|
SetNodeAffinity(&kd.Deployment.Spec.Template.ObjectMeta, MasterNodeAffinity(), NativeArchitectureNodeAffinity())
|
||||||
|
|
||||||
return kd
|
return kd
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user