k8s资源对象的label操做
k8s资源对象的label操做查看需要更改标签的pod[root@kubernetes k8s]# kubectl get podsNAMEREADYSTATUSRESTARTSAGEclient0/1Error0140d...
k8s资源对象的label操做
查看需要更改标签的pod
[root@kubernetes k8s]# kubectl get pods
NAME READY STATUS RESTARTS AGE
client 0/1 Error 0 140d
myapp-9b4987d5-slkqx 1/1 Running 2 140d
myapp-9b4987d5-vbs7h 1/1 Running 2 140d
myapp-9b4987d5-z9qcg 1/1 Running 2 140d
nginx-deploy-84cbfc56b6-fjzhj 1/1 Running 2 140d
给myapp-9b4987d5-slkqx这个pod添加role=backend标签
[root@kubernetes k8s]# kubectl label pod myapp-9b4987d5-slkqx role=backend
pod/myapp-9b4987d5-slkqx labeled
[root@kubernetes k8s]# kubectl get pods -lrole
NAME READY STATUS RESTARTS AGE
myapp-9b4987d5-slkqx 1/1 Running 2 140d
查看myapp-9b4987d5-slkqx,注意ROLR和其下的backend
[root@kubernetes k8s]# kubectl get pods -Lrole
NAME READY STATUS RESTARTS AGE ROLE
client 0/1 Error 0 140d
myapp-9b4987d5-slkqx 1/1 Running 2 140d backend
myapp-9b4987d5-vbs7h 1/1 Running 2 140d
myapp-9b4987d5-z9qcg 1/1 Running 2 140d
nginx-deploy-84cbfc56b6-fjzhj 1/1 Running 2 140d
修改标签,将role=backend改为role=master,命令后需要添加 --overwrite
[root@kubernetes k8s]# kubectl label pod myapp-9b4987d5-slkqx role=master --overwrite
pod/myapp-9b4987d5-slkqx labeled
[root@kubernetes k8s]# kubectl get pods -Lrole
NAME READY STATUS RESTARTS AGE ROLE
client 0/1 Error 0 140d
myapp-9b4987d5-slkqx 1/1 Running 2 140d master
myapp-9b4987d5-vbs7h 1/1 Running 2 140d
myapp-9b4987d5-z9qcg 1/1 Running 2 140d
nginx-deploy-84cbfc56b6-fjzhj 1/1 Running 2 140d
删除标签,将标签后加一个减号相连
[root@kubernetes k8s]# kubectl label pod myapp-9b4987d5-slkqx role-
pod/myapp-9b4987d5-slkqx labeled
[root@kubernetes k8s]# kubectl get pods
NAME READY STATUS RESTARTS AGE
client 0/1 Error 0 140d
myapp-9b4987d5-slkqx 1/1 Running 2 140d
myapp-9b4987d5-vbs7h 1/1 Running 2 140d
myapp-9b4987d5-z9qcg 1/1 Running 2 140d
nginx-deploy-84cbfc56b6-fjzhj 1/1 Running 2 140d
更多推荐
所有评论(0)