Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pod AntiAffinity with PodAffinity + NotIn does not work #6

Open
CrimsonGlory opened this issue Apr 24, 2021 · 0 comments
Open

Pod AntiAffinity with PodAffinity + NotIn does not work #6

CrimsonGlory opened this issue Apr 24, 2021 · 0 comments

Comments

@CrimsonGlory
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant