|NO.Z.00213|——————————|CloudNative|——|KuberNetes&高级调度.V16|——|Pod亲和力反亲和力.v04|pod反亲和力_部署不同主机|

一、若是想把demo-nginx部署在不同的节点上面,
### --- 部署demo-nginx至不同的宿主机上
~~~     编写yaml文件
~~~     demo-nginx就和当前的app下的demo-nginx匹配,不写namespace就是当前的namespace下

[root@k8s-master01 ~]# vim pod-Affinity-demo-nginx.yaml 
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - demo-nginx    
            topologyKey: kubernetes.io/hostname 
### --- replace重新触发一下

[root@k8s-master01 ~]# kubectl replace -f pod-Affinity-demo-nginx.yaml
deployment.apps/demo-nginx replaced
### --- 验证结果
~~~     部署在了k8s-master01和k8s-node01节点上面
~~~     在部署Redis集群和统一业务的集群,尽量不要部署在同一个节点 

[root@k8s-master01 ~]# kubectl get po -owide
NAME                          READY   STATUS        RESTARTS   AGE   IP              NODE           NOMINATED NODE   READINESS GATES
busybox                       1/1     Running       0          36m   172.25.92.90    k8s-master02   <none>           <none>
demo-nginx-7c464c79f7-hg4rm   2/2     Running       0          35s   172.18.195.42   k8s-master03   <none>           <none>
demo-nginx-7c464c79f7-v7pmw   2/2     Running       0          35s   172.17.125.35   k8s-node01     <none>           <none>

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(21)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示