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

  

 

 

上一篇:第二章 ELKstack部署及配置


下一篇:C#代码段 ---- 管理工具