Kubernetes label简单使用

# 查看集群中的node节点
# kubectl get nodes
NAME       STATUS    ROLES     AGE       VERSION
server01   Ready     <none>    130d      v1.9.2
server02   Ready     <none>    130d      v1.9.2
server03   Ready     <none>    130d      v1.9.2

# 查看server02的具体信息
# kubectl describe node server02
Name:               server02
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/hostname=server02

# 为server02添加label:xx=yy
# kubectl label nodes server02 xx=yy
node "server02" labeled

# 此时server02已有xx=yy的label
# kubectl describe node server02
Name:               server02
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/hostname=server02
                    xx=yy

# 获取label为xx=yy的node,可以查到server02
# kubectl get node -a -l "xx=yy"
NAME       STATUS    ROLES     AGE       VERSION
server02   Ready     <none>    130d      v1.9.2

# 修改xx=yy为xx=zz
# kubectl label --overwrite nodes server02 xx=zz
node "server02" labeled

# kubectl describe node server02
Name:               server02
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/hostname=server02
                    xx=zz

# 删除server02上的xx标签
# kubectl label nodes server02 xx-
node "server02" labeled

# 查找xx=zz的节点,已经显示没有
# kubectl get node -a -l "xx=zz"
No resources found.

 

posted on 2019-03-19 15:40  floud  阅读(452)  评论(0编辑  收藏  举报