pod 的亲和性,反亲和性 实验
生活随笔
收集整理的這篇文章主要介紹了
pod 的亲和性,反亲和性 实验
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
文章目錄
- 1 ,環(huán)境準備
- 2 親和性+ In 測試
- 3 親和性+NotIn 測試
- 4 非親和性+In 測試
- 5 非親和性 + NotIn 測試
1 ,環(huán)境準備
node01、 node02 都有標簽 test=a,有個pod1 運行在node01上, 標簽為app=myapp01
#設置node01和node02節(jié)點,擁有標簽 test=a [root@master demo]# kubectl label nodes node{01,02} test=a --overwrite node/node01 labeled node/node02 labeled#查看擁有標簽test=a的節(jié)點 [root@master demo]# kubectl get nodes -l test=a NAME STATUS ROLES AGE VERSION node01 Ready <none> 7d6h v1.15.1 node02 Ready <none> 7d6h v1.15.1 [root@master demo]# vim test.yaml apiVersion: v1 kind: Pod metadata:name: myapp01labels:app: myapp01 spec:containers:- name: with-node-affinityimage: soscscs/myapp:v1 #聲明式創(chuàng)建pod [root@master demo]# kubectl apply -f test.yaml pod/myapp01 created#查看pod myapp01的詳細信息的標簽 [root@master demo]# kubectl get pods myapp01 -o wide --show-labels NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS myapp01 1/1 Running 0 26s 10.244.1.112 node01 <none> <none> app=myapp012 親和性+ In 測試
[root@master demo]# vim a.yaml apiVersion: v1 kind: Pod metadata:name: myapp10labels:app: myapp03 spec:containers:- name: myapp03image: soscscs/myapp:v1affinity:podAffinity:requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:matchExpressions:- key: appoperator: Invalues:- myapp01topologyKey: testpod擁有app=myapp01 標簽(設這個pod為x),則把新pod調(diào)度到和 pod x 擁有同一個拓撲域test=a 的 節(jié)點上。
[root@master demo]# for i in myapp{11..15}; do kubectl apply -f a.yaml; sed -ri "4s#myapp1[0-9]#$i#" a.yaml; done pod/myapp10 created pod/myapp11 created pod/myapp12 created pod/myapp13 created pod/myapp14 created [root@master demo]# kubectl get pods -o wide --show-labels NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS myapp01 1/1 Running 0 88m 10.244.1.112 node01 <none> <none> app=myapp01 myapp10 1/1 Running 0 6s 10.244.2.104 node02 <none> <none> app=myapp03 myapp11 1/1 Running 0 6s 10.244.1.138 node01 <none> <none> app=myapp03 myapp12 1/1 Running 0 5s 10.244.2.105 node02 <none> <none> app=myapp03 myapp13 1/1 Running 0 5s 10.244.1.139 node01 <none> <none> app=myapp03 myapp14 1/1 Running 0 5s 10.244.2.106 node02 <none> <none> app=myapp03因為拓撲域test=a內(nèi),已經(jīng)有了pod存在于node01節(jié)點上,所以
3 親和性+NotIn 測試
[root@master demo]# vim a.yaml apiVersion: v1 kind: Pod metadata:name: myapp10labels:app: myapp03 spec:containers:- name: myapp03image: soscscs/myapp:v1affinity:podAffinity:requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:matchExpressions:- key: appoperator: NotInvalues:- myapp01topologyKey: test [root@master demo]# kubectl delete pod myapp{10..14};for i in myapp{11..15}; do kubectl apply -f a.yaml; sed -ri "4s#myapp1[0-9]#$i#" a.yaml; done pod "myapp10" deleted pod "myapp11" deleted pod "myapp12" deleted pod "myapp13" deleted pod "myapp14" deleted pod/myapp10 created pod/myapp11 created pod/myapp12 created pod/myapp13 created pod/myapp14 created [root@master demo]# kubectl get pods -o wide --show-labels NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS myapp01 1/1 Running 0 91m 10.244.1.112 node01 <none> <none> app=myapp01 myapp10 1/1 Running 0 5s 10.244.1.140 node01 <none> <none> app=myapp03 myapp11 1/1 Running 0 5s 10.244.2.107 node02 <none> <none> app=myapp03 myapp12 1/1 Running 0 4s 10.244.1.141 node01 <none> <none> app=myapp03 myapp13 1/1 Running 0 4s 10.244.2.108 node02 <none> <none> app=myapp03 myapp14 1/1 Running 0 4s 10.244.1.142 node01 <none> <none> app=myapp034 非親和性+In 測試
[root@master demo]# vim a.yaml apiVersion: v1 kind: Pod metadata:name: myapp10labels:app: myapp03 spec:containers:- name: myapp03image: soscscs/myapp:v1affinity:podAntiAffinity:requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:matchExpressions:- key: appoperator: Invalues:- myapp01topologyKey: test [root@master demo]# kubectl delete pod myapp{10..14};for i in myapp{11..15}; do kubectl apply -f a.yaml; sed -ri "4s#myapp1[0-9]#$i#" a.yaml; done pod "myapp10" deleted pod "myapp11" deleted pod "myapp12" deleted pod "myapp13" deleted pod "myapp14" deleted pod/myapp10 created pod/myapp11 created pod/myapp12 created pod/myapp13 created pod/myapp14 created [root@master demo]# kubectl get pods -o wide --show-labels NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS myapp01 1/1 Running 0 96m 10.244.1.112 node01 <none> <none> app=myapp01 myapp10 0/1 Pending 0 4s <none> <none> <none> <none> app=myapp03 myapp11 0/1 Pending 0 3s <none> <none> <none> <none> app=myapp03 myapp12 0/1 Pending 0 3s <none> <none> <none> <none> app=myapp03 myapp13 0/1 Pending 0 3s <none> <none> <none> <none> app=myapp03 myapp14 0/1 Pending 0 3s <none> <none> <none> <none> app=myapp03[root@master demo]# kubectl describe pod myapp105 非親和性 + NotIn 測試
[root@master demo]# vim a.yaml apiVersion: v1 kind: Pod metadata:name: myapp10labels:app: myapp03 spec:containers:- name: myapp03image: soscscs/myapp:v1affinity:podAntiAffinity:requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:matchExpressions:- key: appoperator: NotInvalues:- myapp01topologyKey: test [root@master demo]# kubectl delete pod myapp{10..14};for i in myapp{11..15}; do kubectl apply -f a.yaml; sed -ri "4s#myapp1[0-9]#$i#" a.yaml; done pod "myapp10" deleted pod "myapp11" deleted pod "myapp12" deleted pod "myapp13" deleted pod "myapp14" deleted pod/myapp10 created pod/myapp11 created pod/myapp12 created pod/myapp13 created pod/myapp14 created [root@master demo]# kubectl get pods -o wide --show-labels NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS myapp01 1/1 Running 0 102m 10.244.1.112 node01 <none> <none> app=myapp01 myapp10 1/1 Running 0 8s 10.244.2.109 node02 <none> <none> app=myapp03 myapp11 0/1 Pending 0 8s <none> <none> <none> <none> app=myapp03 myapp12 0/1 Pending 0 7s <none> <none> <none> <none> app=myapp03 myapp13 0/1 Pending 0 7s <none> <none> <none> <none> app=myapp03 myapp14 0/1 Pending 0 7s <none> <none> <none> <none> app=myapp03[root@master demo]# kubectl describe pod myapp11總結(jié)
以上是生活随笔為你收集整理的pod 的亲和性,反亲和性 实验的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: k8s的list-watch机制和 po
- 下一篇: k8s资源控制(污点和容忍)