摘要在Kubernetes中,节点(Node)标签(Labels)是用来对集群中的节点进行分类和组织的一种机制。节点标签可以用于定义节点的特性、功能或角色。 使用节点标签可以使集群管理...
1、查看集群节点信息
[root@k8s-master1 ~]# kubectl get nodes
2、定义标签
定义k8s-node1标签为worker1,定义k8s-node2标签为worker2,定义k8s-node3标签为worker3
[root@k8s-master1 ~]# kubectl label node k8s-node1 kubernetes.io/role=worker1
node/k8s-node1 labeled
[root@k8s-master1 ~]# kubectl label node k8s-node2 kubernetes.io/role=worker2
node/k8s-node2 labeled
[root@k8s-master1 ~]# kubectl label node k8s-node3 kubernetes.io/role=worker3
node/k8s-node3 labeled
定义k8s-master1、k8s-master2、k8s-master3标签为master
[root@k8s-master1 ~]# kubectl label node k8s-master1 kubernetes.io/role=master
node/k8s-master1 labeled
[root@k8s-master1 ~]# kubectl label node k8s-master2 kubernetes.io/role=master
node/k8s-master2 labeled
[root@k8s-master1 ~]# kubectl label node k8s-master3 kubernetes.io/role=master
node/k8s-master3 labeled
[root@k8s-master1 ~]# kubectl get nodes
3、更换标签
[root@k8s-master1 ~]# kubectl label nodes k8s-node1 kubernetes.io/role=worker --overwrite
node/k8s-node1 labeled
[root@k8s-master1 ~]# kubectl label nodes k8s-node2 kubernetes.io/role=worker --overwrite
node/k8s-node2 labeled
[root@k8s-master1 ~]# kubectl label nodes k8s-node3 kubernetes.io/role=worker --overwrite
node/k8s-node3 labeled
[root@k8s-master1 ~]# kubectl get nodes
4、移除标签
[root@k8s-master1 ~]# kubectl label nodes k8s-node1 kubernetes.io/role-
node/k8s-node1 unlabeled
[root@k8s-master1 ~]# kubectl label nodes k8s-node2 kubernetes.io/role-
node/k8s-node2 unlabeled
[root@k8s-master1 ~]# kubectl label nodes k8s-node3 kubernetes.io/role-
node/k8s-node3 unlabeled
[root@k8s-master1 ~]# kubectl get nodes
历史上的今天
10 月
18