您好,登录后才能下订单哦!
这篇文章主要介绍“k8s怎么给node添加标签”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“k8s怎么给node添加标签”文章能帮助大家解决问题。
k8s集群如果由大量节点组成,可将节点打上对应的标签,然后通过标签进行筛选及查看,更好的进行资源对象的相关选择与匹配
[root@master01 ~]# kubectl get node --show-labels NAME STATUS ROLES AGE VERSION LABELS master01 Ready control-plane,master 3d10h v1.21.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=,node.kubernetes.io/exclude-from-external-load-balancers= worker01 Ready <none> 3d9h v1.21.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=worker01,kubernetes.io/os=linux,region=huanan worker02 Ready <none> 3d9h v1.21.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=worker02,kubernetes.io/os=linux
[root@master01 ~]# kubectl label node worker02 region=guanzhou
node/worker02 labeled
[root@master01 ~]# kubectl get nodes -L region
NAME STATUS ROLES AGE VERSION REGION
master01 Ready control-plane,master 3d10h v1.21.0
worker01 Ready <none> 3d9h v1.21.0 huanan
worker02 Ready <none> 3d9h v1.21.0 guanzhou
也可以加其它的多维度标签,用于不同的需要区分的场景
如把worker01
标签为华南区,A机房,测试环境,游戏业务
[root@master01 ~]# kubectl label node worker01 zone=A env=test bussiness=game
node/worker01 labeled
[root@master01 ~]# kubectl get node -L zone,env
NAME STATUS ROLES AGE VERSION ZONE ENV
master01 Ready control-plane,master 3d10h v1.21.0
worker01 Ready <none> 3d9h v1.21.0 A test
worker02 Ready <none> 3d9h v1.21.0
[root@master01 ~]# kubectl get nodes -l env=test --show-labels
NAME STATUS ROLES AGE VERSION LABELS
worker01 Ready <none> 3d9h v1.21.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,bussiness=game,env=test,kubernetes.io/arch=amd64,kubernetes.io/hostname=worker01,kubernetes.io/os=linux,region=huanan,zone=A
[root@master01 ~]# kubectl label node worker01 env=prod --overwrite=true
node/worker01 labeled
[root@master01 ~]# kubectl label node worker01 env-
node/worker01 labeled
[root@master01 ~]# kubectl get node -L env
NAME STATUS ROLES AGE VERSION ENV
master01 Ready control-plane,master 3d10h v1.21.0
worker01 Ready <none> 3d9h v1.21.0
worker02 Ready <none> 3d9h v1.21.0
[root@master01 ~]# kubectl label node worker01 env=test1
node/worker01 labeled
[root@master01 ~]# kubectl label node worker02 env=test2
node/worker02 labeled
[root@master01 ~]# kubectl get node -l 'env in(test1,test2)'
NAME STATUS ROLES AGE VERSION
worker01 Ready <none> 3d9h v1.21.0
worker02 Ready <none> 3d9h v1.21.0
[root@master01 ~]# kubectl get node -l 'env in(test1,test2)' --show-labels
NAME STATUS ROLES AGE VERSION LABELS
worker01 Ready <none> 3d9h v1.21.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,bussiness=game,env=test1,kubernetes.io/arch=amd64,kubernetes.io/hostname=worker01,kubernetes.io/os=linux,region=huanan,zone=A
worker02 Ready <none> 3d9h v1.21.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,env=test2,kubernetes.io/arch=amd64,kubernetes.io/hostname=worker02,kubernetes.io/os=linux,region=guanzhou
关于“k8s怎么给node添加标签”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。