Here, we show as shortly as possible how we can place a POD on the controlplane node on killerkoda CKA playground:
Task: place a POD on the controlplane POD using Affinity
- Find documentation: kubernetes.io –> Documentation –> Search „affinity“
–> you will find: Assign Pods to Nodes using Node Affinity | Kubernetes
# create POD YAML: k run mypod--image nginx -o yaml --dry-run=client > pod.yaml # edit pod.yaml (in killerkoda you can use the editor that helps with the syntax. Also look in the documentation above): apiVersion: v1 kind: Pod metadata: labels: run: mypod name: mypod spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: myKey operator: In values: - "label1" - "label2" # create pod k apply -f pod.yaml # check pod location k get pod -o wide # check, why the pod is in Pending state: k describe pod mypod | grep -A 100 Events: # add a matching label to the controlplane node k label nodes controlplane myKey=label1 # the pod is still not scheduled because of a taint. View taints: k describe nodes controlplane | grep -i taint # remove taint k taint node controlplane node-role.kubernetes.io/control-plane:NoSchedule- # now the pod is scheduled k get pod -o wide
Reference
- Long ago, we had written quite lengthy blog posts about Node Selectors and various scenarios on how to use Node Affinity and Anti-Affinity: