zoukankan      html  css  js  c++  java
  • 给k8s集群中的node节点加标签

     

     

    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



  • 相关阅读:
    Windows Server 2003 SP2(32位) 中文版 下载地址 光盘整合方法
    用Recycle()方法对Java对象的重要性
    Lotus中千奇百怪的 $$
    Developing a simple application using steps "User Decision" and "Mail"(1) 沧海
    沟通中的情绪管理(演讲稿) 沧海
    人只有在压力之下,才可能成功,没做一件事,都必须成功,不许言败 沧海
    什么是IDOC,以及IDOC的步骤 沧海
    VS2008 Professional Edition CHS中的deffactory.dat读取错误 沧海
    Including custom text in the step "User Decision" 沧海
    SAP Upgrade Strategy 沧海
  • 原文地址:https://www.cnblogs.com/cheyunhua/p/14445989.html
Copyright © 2011-2022 走看看