pod 反親和測試驗證

場景需求

node 節點上不允許有兩個一樣的pod,即每個節點上每個應用僅僅允許一個pod 運行
  • 測試yaml
[root@k8sNode0 podqinhexing]# cat test.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 4
  template:
    metadata:
      labels:
        app: nginx
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - nginx
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: nginx-server
        image: nginx:latest

  • 測試結果(第四個pod 顯示pending 狀態,即每個節點上落了一個pod)
[root@k8sNode0 podqinhexing]# kubectl  get pod   -o wide |grep nginx
nginx-78dfb97767-747w5                         1/1     Running   0          8s     172.16.4.183   cn-zhangjiakou.172.16.4.39   <none>           <none>
nginx-78dfb97767-bgl2n                         1/1     Running   0          8s     172.16.4.243   cn-zhangjiakou.172.16.4.40   <none>           <none>
nginx-78dfb97767-hrbrn                         1/1     Running   0          8s     172.16.4.16    cn-zhangjiakou.172.16.4.38   <none>           <none>
nginx-78dfb97767-qmjc9                         0/1     Pending   0          8s     <none>         <none>                       <none>           <none>

  • 第四個pod 的報錯日誌
  Warning  FailedScheduling  15s   default-scheduler  0/3 nodes are available: 3 node(s) didn't match pod anti-affinity rules. preemption: 0/3 nodes are available: 3 No preemption victims found for incoming pod.,


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章