您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么給k8s集群里的資源打標(biāo)簽”的相關(guān)知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“怎么給k8s集群里的資源打標(biāo)簽”文章能幫助大家解決問題。
給節(jié)點添加角色:
k8s集群,節(jié)點如果有多個角色,需要標(biāo)記出來,可以給對應(yīng)的節(jié)點打上標(biāo)簽,方便后續(xù)了解節(jié)點的功能
命令:kubectl label nodes 節(jié)點名字 node-role.kubernetes.io/你想要的roles(=/-)
最后括號里的加減號,減號就是刪除roles,等號就是增加roles
更新標(biāo)簽,在打標(biāo)簽命令后面添加參數(shù)--overwrite
舉例:
給node節(jié)點添加角色:
#給node1節(jié)點增加jenkins角色 [root@k8s-master1 ~]# kubectl label nodes k8s-node1 node-role.kubernetes.io/jenkins= node/k8s-node1 labeled #給node2節(jié)點增加gitlab角色 [root@k8s-master1 ~]# kubectl label nodes k8s-node2 node-role.kubernetes.io/gitlab= node/k8s-node2 labeled #查詢節(jié)點roles [root@k8s-master1 ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master1 Ready master 17d v1.19.4 k8s-node1 Ready jenkins,node 17d v1.19.4 k8s-node2 Ready gitlab,node 14d v1.19.4
給deploymen控制器打標(biāo)簽:
更新標(biāo)簽,在打標(biāo)簽命令后面添加參數(shù)--overwrite
#查詢標(biāo)簽 [root@k8s-master1 k8s]# kubectl get deploy -n my-ns-kcxm kcxm --show-labels NAME READY UP-TO-DATE AVAILABLE AGE LABELS kcxm 2/2 2 2 8m47s app=kcxm-gc #打標(biāo)簽version=v1 [root@k8s-master1 k8s]# kubectl label deploy -n my-ns-kcxm kcxm version=v1 deployment.apps/kcxm labeled #查詢標(biāo)簽 [root@k8s-master1 k8s]# kubectl get deploy -n my-ns-kcxm kcxm --show-labels NAME READY UP-TO-DATE AVAILABLE AGE LABELS kcxm 2/2 2 2 9m19s app=kcxm-gc,version=v1 #更新標(biāo)簽,在打標(biāo)簽命令后面添加參數(shù)--overwrite [root@k8s-master1 k8s]# kubectl label deploy -n my-ns-kcxm kcxm version=v2 --overwrite deployment.apps/kcxm labeled #查詢標(biāo)簽 [root@k8s-master1 k8s]# kubectl get deploy -n my-ns-kcxm kcxm --show-labels NAME READY UP-TO-DATE AVAILABLE AGE LABELS kcxm 2/2 2 2 13m app=kcxm-gc,version=v2 #刪除標(biāo)簽version=v2 [root@k8s-master1 k8s]# kubectl label deploy -n my-ns-kcxm kcxm version- deployment.apps/kcxm labeled #查詢標(biāo)簽 [root@k8s-master1 k8s]# kubectl get deploy -n my-ns-kcxm kcxm --show-labels NAME READY UP-TO-DATE AVAILABLE AGE LABELS kcxm 2/2 2 2 9m30s app=kcxm-gc
給pod打標(biāo)簽:
[root@k8s-master1 k8s]# kubectl get pod -n my-ns-kcxm --show-labels NAME READY STATUS RESTARTS AGE LABELS kcxm-84c56f9d5b-595qx 1/1 Running 0 2m42s app=kcxm-gc,pod-template-hash=84c56f9d5b kcxm-84c56f9d5b-6h5w2 1/1 Running 0 2m42s app=kcxm-gc,pod-template-hash=84c56f9d5b #給pod打標(biāo)簽version=1.23.1 [root@k8s-master1 k8s]# kubectl label pod -n my-ns-kcxm kcxm-84c56f9d5b-595qx version=1.23.1 pod/kcxm-84c56f9d5b-595qx labeled #查詢標(biāo)簽 [root@k8s-master1 k8s]# kubectl get pod -n my-ns-kcxm --show-labels NAME READY STATUS RESTARTS AGE LABELS kcxm-84c56f9d5b-595qx 1/1 Running 0 3m30s app=kcxm-gc,pod-template-hash=84c56f9d5b,version=1.23.1 kcxm-84c56f9d5b-6h5w2 1/1 Running 0 3m30s app=kcxm-gc,pod-template-hash=84c56f9d5b #給pod刪除標(biāo)簽version=1.23.1 [root@k8s-master1 k8s]# kubectl label pod -n my-ns-kcxm kcxm-84c56f9d5b-595qx version- pod/kcxm-84c56f9d5b-595qx labeled #刪除標(biāo)簽 [root@k8s-master1 k8s]# kubectl get pod -n my-ns-kcxm --show-labels NAME READY STATUS RESTARTS AGE LABELS kcxm-84c56f9d5b-595qx 1/1 Running 0 4m7s app=kcxm-gc,pod-template-hash=84c56f9d5b kcxm-84c56f9d5b-6h5w2 1/1 Running 0 4m7s app=kcxm-gc,pod-template-hash=84c56f9d5b
[root@k8s-master ~]# hostname #查看節(jié)點名稱 k8s-master [root@k8s-master ~]# [root@k8s-master ~]# kubectl get nodes --show-labels #查看節(jié)點標(biāo)簽 NAME STATUS ROLES AGE VERSION LABELS k8s-master Ready control-plane 9d v1.26.0 app=master,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers= [root@k8s-master ~]# kubectl label nodes k8s-master env=env #給節(jié)點添加一個標(biāo)簽env=env node/k8s-master labeled [root@k8s-master ~]# kubectl get nodes --show-labels #再次查看節(jié)點標(biāo)簽,確定標(biāo)簽添加上了 NAME STATUS ROLES AGE VERSION LABELS k8s-master Ready control-plane 9d v1.26.0 app=master,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,env=env,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers= [root@k8s-master ~]# kubectl label nodes k8s-master env- #刪除節(jié)點標(biāo)簽env=env node/k8s-master unlabeled [root@k8s-master ~]# [root@k8s-master ~]# kubectl get nodes --show-labels #再次查看確定標(biāo)簽已經(jīng)刪除了 NAME STATUS ROLES AGE VERSION LABELS k8s-master Ready control-plane 9d v1.26.0 app=master,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers= [root@k8s-master ~]#
關(guān)于“怎么給k8s集群里的資源打標(biāo)簽”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。