kubernetes 两个部署有相同的规格,那复制体是怎么知道他们拥有哪些吊舱的?

xqkwcwgp  于 2023-04-20  发布在  Kubernetes
关注(0)|答案(1)|浏览(130)

下面给出了两个部署,它们只在名称上推迟。

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: deployment-1
  5. spec:
  6. replicas: 2
  7. selector:
  8. matchLabels:
  9. app: myapp
  10. template:
  11. metadata:
  12. labels:
  13. app: myapp
  14. spec:
  15. containers:
  16. - name: myapp
  17. image: nginx:1.11
  18. ---
  19. apiVersion: apps/v1
  20. kind: Deployment
  21. metadata:
  22. name: deployment-2
  23. spec:
  24. replicas: 2
  25. selector:
  26. matchLabels:
  27. app: myapp
  28. template:
  29. metadata:
  30. labels:
  31. app: myapp
  32. spec:
  33. containers:
  34. - name: myapp
  35. image: nginx:1.11

应用上述方法将生成两个部署和两个复制集。

  1. kubectl get replicasets
  2. NAME DESIRED CURRENT READY AGE
  3. deployment-1-8684779b48 2 2 2 34m
  4. deployment-2-8684779b48 2 2 2 34m

复制集的描述如下-

  1. kubectl describe replicaset deployment-1
  2. Name: deployment-1-8684779b48
  3. Namespace: default
  4. Selector: app=myapp,pod-template-hash=8684779b48
  5. Labels: app=myapp
  6. pod-template-hash=8684779b48
  7. Annotations: deployment.kubernetes.io/desired-replicas: 2
  8. deployment.kubernetes.io/max-replicas: 3
  9. deployment.kubernetes.io/revision: 1
  10. Controlled By: Deployment/deployment-1
  11. Replicas: 2 current / 2 desired
  12. Pods Status: 2 Running / 0 Waiting / 0 Succeeded / 0 Failed
  13. Pod Template:
  14. Labels: app=myapp
  15. pod-template-hash=8684779b48
  16. Containers:
  17. myapp:
  18. Image: nginx:1.11
  19. Port: <none>
  20. Host Port: <none>
  21. Environment: <none>
  22. Mounts: <none>
  23. Volumes: <none>
  24. Events:
  25. Type Reason Age From Message
  26. ---- ------ ---- ---- -------
  27. Normal SuccessfulCreate 35m replicaset-controller Created pod: deployment-1-8684779b48-ngm5l
  28. Normal SuccessfulCreate 35m replicaset-controller Created pod: deployment-1-8684779b48-5fz94
  29. Normal SuccessfulCreate 34m replicaset-controller Created pod: deployment-1-8684779b48-svphx
  30. Normal SuccessfulCreate 33m replicaset-controller Created pod: deployment-1-8684779b48-q7lh5

还有-

  1. kubectl describe replicaset deployment-2
  2. Name: deployment-2-8684779b48
  3. Namespace: default
  4. Selector: app=myapp,pod-template-hash=8684779b48
  5. Labels: app=myapp
  6. pod-template-hash=8684779b48
  7. Annotations: deployment.kubernetes.io/desired-replicas: 2
  8. deployment.kubernetes.io/max-replicas: 3
  9. deployment.kubernetes.io/revision: 1
  10. Controlled By: Deployment/deployment-2
  11. Replicas: 2 current / 2 desired
  12. Pods Status: 2 Running / 0 Waiting / 0 Succeeded / 0 Failed
  13. Pod Template:
  14. Labels: app=myapp
  15. pod-template-hash=8684779b48
  16. Containers:
  17. myapp:
  18. Image: nginx:1.11
  19. Port: <none>
  20. Host Port: <none>
  21. Environment: <none>
  22. Mounts: <none>
  23. Volumes: <none>
  24. Events:
  25. Type Reason Age From Message
  26. ---- ------ ---- ---- -------
  27. Normal SuccessfulCreate 36m replicaset-controller Created pod: deployment-2-8684779b48-w4zws
  28. Normal SuccessfulCreate 36m replicaset-controller Created pod: deployment-2-8684779b48-nfzxb

在上面,两个副本集都有相同的选择器值Selector: app=myapp,pod-template-hash=8684779b48现在这两个副本集如何确定下面的哪些pod属于它们,因为它们都有相同的标签-

  1. kubectl get pods -l app=myapp -l pod-template-hash=8684779b48
  2. NAME READY STATUS RESTARTS AGE
  3. deployment-1-8684779b48-q7lh5 1/1 Running 0 38m
  4. deployment-1-8684779b48-svphx 1/1 Running 0 39m
  5. deployment-2-8684779b48-nfzxb 1/1 Running 0 40m
  6. deployment-2-8684779b48-w4zws 1/1 Running 0 40m

复制集输出中的Events:信息是否会被使用。否则有人能提供一些信息吗?

axr492tv

axr492tv1#

ReplicaSet与其Pod的链接是通过Pods的metadata.ownerReferences字段,该字段指定当前对象所拥有的资源。ReplicaSet获取的所有Pod都在其ownerReferences字段中具有其所属ReplicaSet的标识信息。通过此链接,ReplicaSet知道它正在维护的Pod的状态并相应地进行计划。
此外,
pod-template-hash标签由Deployment控制器添加到Deployment创建或采用的每个ReplicaSet。
此标签确保Deployment的子ReplicaSet不重叠。它是通过对ReplicaSet的PodTemplate进行散列,并使用所得散列作为添加到ReplicaSet选择器、Pod模板标签以及ReplicaSet可能具有的任何现有Pod中的标签值而生成的。

相关问题