设置k8s中节点node的ROLES值
1.查看集群
bash
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 54d v1.23.8
k8s-node1 Ready <none> 54d v1.23.8
k8s-node2 Ready <none> 54d v1.23.8
2. 给node节点修改roles
其实这个Roles就是一个标签,执行以下命令给node1 和 node2 打上worker标签
k8s-node1 打上标签为worker1
k8s-node2 打上标签为worker2
bash
kubectl label node k8s-node1 kubernetes.io/role=worker1
kubectl label node k8s-node2 kubernetes.io/role=worker2
bash
[root@k8s-master ~]# kubectl label node k8s-node2 kubernetes.io/role=worker2
node/k8s-node2 labeled
[root@k8s-master ~]# kubectl label node k8s-node1 kubernetes.io/role=worker1
node/k8s-node1 labeled
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 54d v1.23.8
k8s-node1 Ready worker1 54d v1.23.8
k8s-node2 Ready worker2 54d v1.23.8
[root@k8s-master ~]#
3.更换为其他的标签
bash
kubectl label nodes k8s-node1 kubernetes.io/role=worker --overwrite
kubectl label nodes k8s-node2 kubernetes.io/role=worker --overwrite
bash
[root@k8s-master ~]# kubectl label nodes k8s-node1 kubernetes.io/role=worker --overwrite
node/k8s-node1 unlabeled
[root@k8s-master ~]# kubectl label nodes k8s-node2 kubernetes.io/role=worker --overwrite
node/k8s-node2 unlabeled
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 54d v1.23.8
k8s-node1 Ready worker 54d v1.23.8
k8s-node2 Ready worker 54d v1.23.8
[root@k8s-master ~]#
4. 不想要标签想移除标签
bash
kubectl label nodes k8s-node1 kubernetes.io/role-
kubectl label nodes k8s-node2 kubernetes.io/role-
bash
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 54d v1.23.8
k8s-node1 Ready <none> 54d v1.23.8
k8s-node2 Ready <none> 54d v1.23.8
[root@k8s-master ~]#