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.答案

  1. 先创建deployment.yaml
    1. kubectl create deploy deploy-important -n dev --image=nginx \
    2. --dry-run=client -oyaml > 12.yaml
    编辑该yaml
    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. creationTimestamp: null
    5. labels:
    6. id: very-important # change
    7. name: deploy-important
    8. namespace: dev
    9. spec:
    10. replicas: 3 # change
    11. selector:
    12. matchLabels:
    13. id: very-important # change
    14. strategy: {}
    15. template:
    16. metadata:
    17. creationTimestamp: null
    18. labels:
    19. id: very-important # change
    20. spec:
    21. containers:
    22. - image: nginx:1.17.6-alpine
    23. name: container1 # change
    24. resources: {}
    25. - image: kubernetes/pause # add
    26. name: container2 # add
    27. affinity: # add
    28. podAntiAffinity: # add
    29. requiredDuringSchedulingIgnoredDuringExecution: # add
    30. - labelSelector: # add
    31. matchExpressions: # add
    32. - key: id # add
    33. operator: In # add
    34. values: # add
    35. - very-important # add
    36. topologyKey: kubernetes.io/hostname # add
    37. status: {}
    1. kubectl apply -f 12.yaml