k8s修改node的roles标签

k8s修改node的roles标签

Scroll Down

kubeadm部署的k8s集群,执行kubectl get node命令,可以看到如下结果:

[root@k8s01 sanyi-env]# kubectl get node
NAME                 STATUS   ROLES    AGE    VERSION
k8s01.axhome.local   Ready    master   258d   v1.15.4
k8s02.axhome.local   Ready    <none>   115d   v1.15.4
k8s03.axhome.local   Ready    master   258d   v1.15.4
k8s04.axhome.local   Ready    <none>   241d   v1.15.4
k8s05.axhome.local   Ready    <none>   243d   v1.15.4
k8s06.axhome.local   Ready    master   258d   v1.15.4
k8s07.axhome.local   Ready    <none>   243d   v1.15.4
k8s08.axhome.local   Ready    <none>   138d   v1.15.4

node节点除了master有标签,其它node是没有的,如果是二进制部署k8s集群的话,node节点都会没有标签,如下

[root@k8s-master1 ~]# kubectl get node
NAME          STATUS   ROLES    AGE     VERSION
k8s-master1   Ready    <none>   2d22h   v1.18.4
k8s-master2   Ready    <none>   2d17h   v1.18.4
k8s-master3   Ready    <none>   2d17h   v1.18.4
k8s-node1     Ready    <none>   2d20h   v1.18.4
k8s-node2     Ready    <none>   2d21h   v1.18.4

如需给node添加标签,执行如下命令:(k8s-master1为例)

[root@k8s-master1 ~]# kubectl label node k8s-master1 node-role.kubernetes.io/master=
node/k8s-master1 labeled
[root@k8s-master1 ~]# kubectl get node
NAME          STATUS   ROLES    AGE     VERSION
k8s-master1   Ready    master   2d22h   v1.18.4
k8s-master2   Ready    <none>   2d17h   v1.18.4
k8s-master3   Ready    <none>   2d17h   v1.18.4
k8s-node1     Ready    <none>   2d20h   v1.18.4
k8s-node2     Ready    <none>   2d21h   v1.18.4

执行:kubectl describe node k8s-master1 ,可以看到

[root@k8s-master1 ~]# kubectl describe node k8s-master1 
Name:               k8s-master1
Roles:              master
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=k8s-master1
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/master=
Annotations:        flannel.alpha.coreos.com/backend-data: {"VtepMAC":"a2:00:60:fa:d5:d4"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.200.71
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Fri, 26 Jun 2020 15:51:44 +0800

如果,要去掉标签内容,需要执行命令:

[root@k8s-master1 ~]# kubectl label node k8s-master1 node-role.kubernetes.io/master-
node/k8s-master1 labeled
[root@k8s-master1 ~]# kubectl get node
NAME          STATUS   ROLES    AGE     VERSION
k8s-master1   Ready    <none>   2d22h   v1.18.4
k8s-master2   Ready    <none>   2d18h   v1.18.4
k8s-master3   Ready    <none>   2d18h   v1.18.4
k8s-node1     Ready    <none>   2d21h   v1.18.4
k8s-node2     Ready    <none>   2d22h   v1.18.4