[root@k8s-master ~]# hostname #查看节点名称
k8s-master
[root@k8s-master ~]#
[root@k8s-master ~]# kubectl get nodes --show-labels #查看节点标签
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready control-plane 9d v1.26.0 app=master,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=
[root@k8s-master ~]# kubectl label nodes k8s-master env=env #给节点添加一个标签env=env
node/k8s-master labeled
[root@k8s-master ~]# kubectl get nodes --show-labels #再次查看节点标签,确定标签添加上了
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready control-plane 9d v1.26.0 app=master,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,env=env,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=
[root@k8s-master ~]# kubectl label nodes k8s-master env- #删除节点标签env=env
node/k8s-master unlabeled
[root@k8s-master ~]#
[root@k8s-master ~]# kubectl get nodes --show-labels #再次查看确定标签已经删除了
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready control-plane 9d v1.26.0 app=master,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=
[root@k8s-master ~]#