kubernetes Label的增删改查
作者:互联网
查:
[root@k8s-host1 liang]# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS k8s-host1 Ready master 173d v1.16.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,edgenode=true,ingress=yes,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-host1,kubernetes.io/os=linux,node-role.kubernetes.io/master= k8s-host2 Ready master 173d v1.16.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-host2,kubernetes.io/os=linux,node-role.kubernetes.io/master= k8s-host3 Ready master 173d v1.16.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-host3,kubernetes.io/os=linux,node-role.kubernetes.io/master=
增:
# 语法 kubectl label nodes <node-name> <label-key>=<label-value> #给k8s-host1添加一个标签device为ssd [root@k8s-host1 liang]# kubectl label nodes k8s-host1 device=ssd node/k8s-host1 labeled
改:
#语法: 需要加上--overwrite参数: kubectl label nodes <node-name> <label-key>=<label-value> --overwrite [root@k8s-host1 liang]# kubectl label nodes k8s-host1 device=liang --overwrite node/k8s-host1 labeled
#查看修改:
[root@k8s-host1 liang]# kubectl get nodes k8s-host1 --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-host1 Ready master 173d v1.16.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,device=liang,edgenode=true,ingress=yes,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-host1,kubernetes.io/os=linux,node-role.kubernetes.io/master=
删:
# 语法 kubectl label nodes <node-name> <label-key>- [root@k8s-host1 liang]# kubectl label nodes k8s-host1 device- node/k8s-host1 labeled #查看删除: [root@k8s-host1 liang]# kubectl get nodes k8s-host1 --show-labels NAME STATUS ROLES AGE VERSION LABELS k8s-host1 Ready master 173d v1.16.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,edgenode=true,ingress=yes,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-host1,kubernetes.io/os=linux,node-role.kubernetes.io/master=
Pod选择Label
# 添加nodeSelector选项用来选择对应的node apiVersion: v1 kind: Pod metadata: name: nginx labels: env: test spec: containers: - name: nginx image: nginx imagePullPolicy: IfNotPresent nodeSelector: disktype: ssd
标签:io,kubernetes,改查,Label,host1,linux,k8s,amd64 来源: https://www.cnblogs.com/thirteen-yang/p/12957305.html