nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate, 2 node(s) didn't match pod affinity/anti-affinity
root@ubuntu:~# cat web-anti-affinity.yaml apiVersion: apps/v1 kind: Deployment metadata: name: web-nginx spec: selector: matchLabels: app: web-nginx replicas: 3 template: metadata: labels: app: web-nginx spec: affinity: #pod 反亲和性, 打散 web-nginx 各个副本 podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: app operator: In values: - web-nginx topologyKey: "kubernetes.io/hostname" containers: - image: nginx imagePullPolicy: IfNotPresent name: web2-worker ports: - containerPort: 8087 protocol: TCP
root@ubuntu:~# kubectl get pod --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE default web-nginx-7bdc6b976b-glwvh 1/1 Running 0 8m52s default web-nginx-7bdc6b976b-pqk86 0/1 Pending 0 8m52s default web-nginx-7bdc6b976b-xzsf2 1/1 Running 0 8m52s kube-system calico-kube-controllers-5978c5f6b5-tk6pg 1/1 Running 0 2d20h kube-system calico-node-6fwpp 1/1 Running 0 2d20h kube-system calico-node-hdkcz 0/1 Running 0 2d20h kube-system calico-node-xldz2 1/1 Running 0 2d20h kube-system coredns-66bff467f8-hlbzk 1/1 Running 0 50m kube-system coredns-66bff467f8-zx85v 1/1 Running 0 49m kube-system etcd-ubuntu 1/1 Running 4 2d20h kube-system kube-apiserver-ubuntu 1/1 Running 7 2d20h kube-system kube-controller-manager-ubuntu 1/1 Running 5 2d20h kube-system kube-proxy-798sq 1/1 Running 0 2d20h kube-system kube-proxy-8hh62 1/1 Running 0 2d20h kube-system kube-proxy-l268b 1/1 Running 0 2d20h kube-system kube-scheduler-ubuntu 1/1 Running 7 2d20h root@ubuntu:~# kubectl -n default describe pod web-nginx-7bdc6b976b-pqk86 Name: web-nginx-7bdc6b976b-pqk86 Namespace: default Priority: 0 Node: <none> Labels: app=web-nginx pod-template-hash=7bdc6b976b Annotations: <none> Status: Pending IP: IPs: <none> Controlled By: ReplicaSet/web-nginx-7bdc6b976b Containers: web2-worker: Image: nginx Port: 8087/TCP Host Port: 0/TCP Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-smzqh (ro) Conditions: Type Status PodScheduled False Volumes: default-token-smzqh: Type: Secret (a volume populated by a Secret) SecretName: default-token-smzqh Optional: false QoS Class: BestEffort Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s node.kubernetes.io/unreachable:NoExecute for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 41s (x9 over 9m21s) default-scheduler 0/3 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate, 2 node(s) didn't match pod affinity/anti-affinity, 2 node(s) didn't satisfy existing pods anti-affinity rules.
允许master
节点部署pod
,使用命令如下:
root@ubuntu:~# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS bogon Ready worker 2d20h v1.18.1 beta.kubernetes.io/arch=arm64,beta.kubernetes.io/os=linux,kubernetes.io/arch=arm64,kubernetes.io/hostname=bogon,kubernetes.io/os=linux,node-role.kubernetes.io/worker=worker cloud Ready worker 2d20h v1.21.1 beta.kubernetes.io/arch=arm64,beta.kubernetes.io/os=linux,kubernetes.io/arch=arm64,kubernetes.io/hostname=cloud,kubernetes.io/os=linux,node-role.kubernetes.io/worker=worker ubuntu Ready master 2d20h v1.18.1 beta.kubernetes.io/arch=arm64,beta.kubernetes.io/os=linux,kubernetes.io/arch=arm64,kubernetes.io/hostname=ubuntu,kubernetes.io/os=linux,node-role.kubernetes.io/master= root@ubuntu:~# kubectl taint nodes --all node-role.kubernetes.io/master- node/ubuntu untainted taint "node-role.kubernetes.io/master" not found taint "node-role.kubernetes.io/master" not found
成功了
root@ubuntu:~# kubectl get pod --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE default web-nginx-7bdc6b976b-glwvh 1/1 Running 0 17m default web-nginx-7bdc6b976b-pqk86 1/1 Running 0 17m default web-nginx-7bdc6b976b-xzsf2 1/1 Running 0 17m
禁止master
部署pod
kubectl taint nodes k8s node-role.kubernetes.io/master=true:NoSchedule