码迷,mamicode.com
首页 > 其他好文 > 详细

给k8s集群中的node节点加标签

时间:2021-02-26 12:55:02      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:pos   loading   present   linux   lock   root   api   none   disk   

 

1.增加节点标签 备注 =:代表增加标签

kubectl label nodes node3 node-role.kubernetes.io/node3=

技术图片

2.减少节点标签 备注 -:代表减少标签

kubectl label nodes node3 node-role.kubernetes.io/node3-

技术图片

 

 

在某些特殊情况下,需要将某些服务固定在一台宿主机上, k8s可以使用label给node节点打上标签来满足这种需求.

Label添加删除和修改

添加label

# 语法
kubectl label nodes <node-name> <label-key>=<label-value> 
# 查看现有node及label
[root@master ~]# kubectl get nodes --show-labels 
NAME     STATUS   ROLES    AGE     VERSION   LABELS
master   Ready    master   54d     v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master,node-role.kubernetes.io/master=
node01   Ready    <none>   54d     v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node01
node02   Ready    <none>   6d19h   v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node02

# 添加一个key为disktype和value为ssd的label
[root@master ~]# kubectl label nodes node01 disktype=ssd
node/node01 labeled

# 查看是否被添加
[root@master ~]# kubectl get nodes --show-labels        
NAME     STATUS   ROLES    AGE     VERSION   LABELS
master   Ready    master   54d     v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master,node-role.kubernetes.io/master=
node01   Ready    <none>   54d     v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/hostname=node01

删除Label

# 语法
kubectl label nodes <node-name> <label-key>-
# 删除key为disktype的label
[root@master ~]# kubectl label nodes node01 disktype-
node/node01 labeled

[root@master ~]# kubectl get nodes --show-labels     
NAME     STATUS   ROLES    AGE     VERSION   LABELS
master   Ready    master   54d     v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master,node-role.kubernetes.io/master=
node01   Ready    <none>   54d     v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node01
node02   Ready    <none>   6d19h   v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node02

修改Label的值,

#语法: 需要加上--overwrite参数:
kubectl label nodes <node-name> <label-key>=<label-value> --overwrite

[root@master ~]# kubectl label nodes node01 disktype=ssd
node/node01 labeled
[root@master ~]# kubectl label nodes node01 disktype=hdd --overwrite
node/node01 labeled
[root@master ~]# kubectl get nodes --show-labels 
NAME     STATUS   ROLES    AGE     VERSION   LABELS
master   Ready    master   54d     v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master,node-role.kubernetes.io/master=
node01   Ready    <none>   54d     v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=hdd,kubernetes.io/hostname=node01
node02   Ready    <none>   6d19h   v1.13.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node02

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



给k8s集群中的node节点加标签

标签:pos   loading   present   linux   lock   root   api   none   disk   

原文地址:https://www.cnblogs.com/cheyunhua/p/14445989.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!