当前位置:  首页>> 技术小册>> Kubernets合辑5-Pod控制器

  1. # 为了方面演示,增加到三个节点,效果更加明显
  2. [root@centos-7-51 ~]# kubectl get node
  3. NAME STATUS ROLES AGE VERSION
  4. centos-7-51 Ready master 10d v1.18.12
  5. centos-7-52 Ready master 10d v1.18.12
  6. centos-7-53 Ready master 10d v1.18.12
  7. centos-7-54 Ready worker 10d v1.18.12
  8. centos-7-55 Ready worker 10d v1.18.12
  9. centos-7-56 Ready worker 7m58s v1.18.12
  10. [root@centos-7-51 ~]# kubectl label node centos-7-54 ssd=true # 打上标签方便区分
  11. [root@centos-7-51 ~]# kubectl label node centos-7-55 ssd=true
  12. [root@centos-7-51 ~]# kubectl label node centos-7-54 cpu=high
  13. [root@centos-7-51 ~]# kubectl label node centos-7-56 cpu=high

节点选择器有两种,一种时直接指定nodeName,另一种是通过 nodeSelector 来根据标签选择:
● 指定nodeName

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: nginx-deploy
  5. spec:
  6. replicas: 5
  7. selector:
  8. matchLabels:
  9. app: nginx
  10. template:
  11. metadata:
  12. labels:
  13. app: nginx
  14. spec:
  15. containers:
  16. - name: nginx-demo
  17. image: linuxduduniao/nginx:v1.0.0
  18. nodeName: centos-7-56
  1. [root@centos-7-51 ~]# kubectl get pod -o wide # 全部调度到 centos-7-56 节点
  2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  3. nginx-deploy-5648cd896-64ktx 1/1 Running 0 5m54s 172.16.5.11 centos-7-56 <none> <none>
  4. nginx-deploy-5648cd896-fgx75 1/1 Running 0 5m54s 172.16.5.13 centos-7-56 <none> <none>
  5. nginx-deploy-5648cd896-fvrlq 1/1 Running 0 5m54s 172.16.5.12 centos-7-56 <none> <none>
  6. nginx-deploy-5648cd896-hzljl 1/1 Running 0 5m54s 172.16.5.15 centos-7-56 <none> <none>
  7. nginx-deploy-5648cd896-qwrb5 1/1 Running 0 5m54s 172.16.5.14 centos-7-56 <none> <none>

使用nodeSelector

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: nginx-deploy
  5. spec:
  6. replicas: 5
  7. selector:
  8. matchLabels:
  9. app: nginx
  10. template:
  11. metadata:
  12. labels:
  13. app: nginx
  14. spec:
  15. containers:
  16. - name: nginx-demo
  17. image: linuxduduniao/nginx:v1.0.0
  18. nodeSelector:
  19. ssd: "true"
  20. cpu: high
  1. [root@centos-7-51 ~]# kubectl get pod -o wide # nodeSelector多个选项之间是 and 关系
  2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  3. nginx-deploy-6d5b594bf5-b7s68 1/1 Running 0 14s 172.16.3.134 centos-7-54 <none> <none>
  4. nginx-deploy-6d5b594bf5-kv5kn 1/1 Running 0 14s 172.16.3.132 centos-7-54 <none> <none>
  5. nginx-deploy-6d5b594bf5-sxsgv 1/1 Running 0 11s 172.16.3.135 centos-7-54 <none> <none>
  6. nginx-deploy-6d5b594bf5-t2p8n 1/1 Running 0 11s 172.16.3.136 centos-7-54 <none> <none>
  7. nginx-deploy-6d5b594bf5-xrrhp 1/1 Running 0 14s 172.16.3.133 centos-7-54 <none> <none>

该分类下的相关小册推荐: