You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Context: video 47 from CKA course (Pod Affinity and Pod Anti-Affinity). Code use to produce pod antiaffinity.
Using this code (PodAffinity + NotIn to achieve PodAntiAffinity) does not work for me. The pod is scheduled on the same node as frontend app. Label app=frontend is present on frontend app.
$ kubectl get pods -o wide --show-labels
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
frontend 1/1 Running 0 86m 10.244.1.47 pool-axe79dmr0-8or0s <none> <none> app=frontend,run=frontend
$ md5sum podaffinity-required.yaml
8e217e52a432bee34d1aab01226d393c podaffinity-required.yaml
$ kubectl apply -f podaffinity-required.yaml
pod/kplabs-pod-affinity created
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
frontend 1/1 Running 0 87m 10.244.1.47 pool-axe79dmr0-8or0s <none> <none>
kplabs-pod-affinity 1/1 Running 0 11s 10.244.1.3 pool-axe79dmr0-8or0s <none> <none>
But using PodAntiAffinity + In does the trick:
$ kubectl delete -f podaffinity-required.yaml
pod "kplabs-pod-affinity" deleted
$ cat podantiaffinity-required.yaml
apiVersion: v1
kind: Pod
metadata:
name: kplabs-pod-affinity
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- frontend
topologyKey: kubernetes.io/hostname
containers:
- name: pod-affinity
image: nginx
$ kubectl apply -f podantiaffinity-required.yaml
pod/kplabs-pod-affinity created
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
frontend 1/1 Running 0 89m 10.244.1.47 pool-axe79dmr0-8or0s <none> <none>
kplabs-pod-affinity 1/1 Running 0 5s 10.244.0.191 worker-node-8ouvr <none> <none>
Other user also had this problem. I'm using the Digital Ocean managed kuberentes created two days ago.
The text was updated successfully, but these errors were encountered:
certified-kubernetes-administrator/Domain 2 - Workloads & Scheduling/podaffinity-required.yaml
Line 12 in 0b014fa
Context: video 47 from CKA course (Pod Affinity and Pod Anti-Affinity). Code use to produce pod antiaffinity.
Using this code (PodAffinity + NotIn to achieve PodAntiAffinity) does not work for me. The pod is scheduled on the same node as frontend app. Label app=frontend is present on frontend app.
But using
PodAntiAffinity
+In
does the trick:Other user also had this problem. I'm using the Digital Ocean managed kuberentes created two days ago.
The text was updated successfully, but these errors were encountered: