1.题目
Create a Deployment named deploy-important with label id=very-important (the pods should also have this label) and 3 replicas in namespace dev. It should contain two containers, the first named container1 with image nginx and the second one named container2 with image kubernetes/pause.
There should be only ever one Pod of that Deployment running on one worker node. We have two worker nodes: cluster1-worker1 and cluster1-worker2. Because the Deployment has three replicas the result should be that on both nodes one Pod is running. The third Pod won’t be scheduled, unless a new worker node will be added.
2.解析
本题目利用deployment来实现DaemonSet,考测pod affinity。
3.答案
- 先创建deployment.yaml
编辑该yamlkubectl create deploy deploy-important -n dev --image=nginx \--dry-run=client -oyaml > 12.yaml
apiVersion: apps/v1kind: Deploymentmetadata:creationTimestamp: nulllabels:id: very-important # changename: deploy-importantnamespace: devspec:replicas: 3 # changeselector:matchLabels:id: very-important # changestrategy: {}template:metadata:creationTimestamp: nulllabels:id: very-important # changespec:containers:- image: nginx:1.17.6-alpinename: container1 # changeresources: {}- image: kubernetes/pause # addname: container2 # addaffinity: # addpodAntiAffinity: # addrequiredDuringSchedulingIgnoredDuringExecution: # add- labelSelector: # addmatchExpressions: # add- key: id # addoperator: In # addvalues: # add- very-important # addtopologyKey: kubernetes.io/hostname # addstatus: {}
kubectl apply -f 12.yaml
