注意:
ROLES列对于的标签名是:kubernetes.io/role
ROLES列对于的标签名是:kubernetes.io/role
ROLES列对于的标签名是:kubernetes.io/role
所以对ROLES列信息的操作,就是对标签名为kubernetes.io/role的操作。
如果ROLES列显示的是
查询当前集群节点信息:
[root@master ~]# kubectl get no
NAME STATUS ROLES AGE VERSION
master Ready master 13d v1.17.4
node1 Ready 13d v1.17.4
node2 Ready 13d v1.17.4
[root@master ~]# kubectl get no -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master Ready master 13d v1.17.4 192.168.48.100 CentOS Linux 7 (Core) 3.10.0-1160.24.1.el7.x86_64 docker://20.10.6
node1 Ready 13d v1.17.4 192.168.48.101 CentOS Linux 7 (Core) 3.10.0-1160.24.1.el7.x86_64 docker://20.10.6
node2 Ready 13d v1.17.4 192.168.48.102 CentOS Linux 7 (Core) 3.10.0-1160.24.1.el7.x86_64 docker://20.10.6
[root@master ~]# kubectl get no -o wide --show-labels
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME LABELS
master Ready master 13d v1.17.4 192.168.48.100 CentOS Linux 7 (Core) 3.10.0-1160.24.1.el7.x86_64 docker://20.10.6 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
node1 Ready 13d v1.17.4 192.168.48.101 CentOS Linux 7 (Core) 3.10.0-1160.24.1.el7.x86_64 docker://20.10.6 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node1,kubernetes.io/os=linux
node2 Ready 13d v1.17.4 192.168.48.102 CentOS Linux 7 (Core) 3.10.0-1160.24.1.el7.x86_64 docker://20.10.6 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node2,kubernetes.io/os=linux
master节点的ROLES列值是master,但node1与node2的ROLES列都是
我们可以通过"kubectl label"命令操作ROLES列的值。
在复习一下本文的重点核心:ROLES列对于的标签名是:kubernetes.io/role
[root@master ~]# kubectl label no node2 kubernetes.io/role=test-node
node/node2 labeled
[root@master ~]# kubectl get no
NAME STATUS ROLES AGE VERSION
master Ready master 13d v1.17.4
node1 Ready 13d v1.17.4
node2 Ready test-node 13d v1.17.4
如果你使用命令“ kubectl label no node1 roles=dev-pc”执行后的信息只在LABELS列中显示。
[root@master ~]# kubectl label no node1 roles=dev-pc
node/node1 labeled
[root@master ~]# kubectl get no
NAME STATUS ROLES AGE VERSION
master Ready master 13d v1.17.4
node1 Ready 13d v1.17.4
node2 Ready test-node 13d v1.17.4
[root@master ~]# kubectl get no --show-labels
NAME STATUS ROLES AGE VERSION LABELS
master Ready master 13d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
node1 Ready 13d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node1,kubernetes.io/os=linux,roles=dev-pc
node2 Ready test-node 13d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node2,kubernetes.io/os=linux,kubernetes.io/role=test-node
与修改标签一样,也要在命令后添加“--overwrite”选项。
node/node2 labeled
[root@master ~]# kubectl get no --show-labels
NAME STATUS ROLES AGE VERSION LABELS
master Ready master 13d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
node1 Ready 13d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node1,kubernetes.io/os=linux,roles=dev-pc
node2 Ready worksation 13d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node2,kubernetes.io/os=linux,kubernetes.io/role=worksation
(1)查询角色是worksation的节点
[root@master ~]# kubectl get no -l kubernetes.io/role=worksation
NAME STATUS ROLES AGE VERSION
node2 Ready worksation 13d v1.17.4
[root@master ~]#
(2)查询没有kubernetes.io/role的节点
[root@master ~]# kubectl get no -l '!kubernetes.io/role'
NAME STATUS ROLES AGE VERSION
master Ready master 13d v1.17.4
node1 Ready 13d v1.17.4
[root@master ~]#
删除ROLES列值的方式与删除label的方式是一样的,只需要在对于的标签名后增加一个减号“-”
[root@master ~]# kubectl label no node2 kubernetes.io/role-
node/node2 labeled
[root@master ~]# kubectl get no
NAME STATUS ROLES AGE VERSION
master Ready master 13d v1.17.4
node1 Ready 13d v1.17.4
node2 Ready 13d v1.17.4
[root@master ~]# kubectl get no --show-labels
NAME STATUS ROLES AGE VERSION LABELS
master Ready master 13d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
node1 Ready 13d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node1,kubernetes.io/os=linux,roles=dev-pc
node2 Ready 13d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node2,kubernetes.io/os=linux
[root@master ~]#