标签:地址 coding bec 系统默认 arc 如何 情况下 div linux
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
[root@kubemaster k8s]# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS kubemaster Ready master 27h v1.18.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=kubemaster,kubernetes.io/os=linux,node-role.kubernetes.io/master= node1 Ready <none> 72m v1.18.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node1,kubernetes.io/os=linux
说明:各node的label都是系统默认的,还没有我们手动添加的
kubectl label nodes <node-name> <label-key>=<label-value>
添加
[root@kubemaster k8s]# kubectl label node kubemaster apptype=web1 node/kubemaster labeled [root@kubemaster k8s]# kubectl label node node1 apptype=web2 node/node1 labeled
[root@kubemaster k8s]# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS kubemaster Ready master 28h v1.18.3 apptype=web1beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=kubemaster,kubernetes.io/os=linux,node-role.kubernetes.io/master= node1 Ready <none> 75m v1.18.3 apptype=web2,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node1,kubernetes.io/os=linux
[root@kubemaster k8s]# kubectl label node node1 apptype=noweb --overwrite
node/node1 labeled
查看效果:
[root@kubemaster k8s]# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS kubemaster Ready master 28h v1.18.3 apptype=web1,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=kubemaster,kubernetes.io/os=linux,node-role.kubernetes.io/master= node1 Ready <none> 85m v1.18.3 apptype=noweb,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node1,kubernetes.io/os=linux
kubectl label nodes <node-name> <label-key>-
删除
[root@kubemaster k8s]# kubectl label nodes node1 apptype-
node/node1 labeled
nodeSelector:
apptype: web
[root@kubemaster k8s]# more nginx-rc.yaml apiVersion: v1 kind: ReplicationController metadata: name: nginx-demo spec: replicas: 2 selector: app: nginx-demo template: metadata: labels: app: nginx-demo spec: nodeSelector: apptype: web containers: - name: nginx-demo image: nginx ports: - containerPort: 80
[root@kubemaster k8s]# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS kubemaster Ready master 28h v1.18.3 apptype=noweb,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=kubemaster,kubernetes.io/os=linux,node-role.kubernetes.io/master= node1 Ready <none> 107m v1.18.3 apptype=web,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node1,kubernetes.io/os=linux
[root@kubemaster k8s]# kubectl apply -f nginx-rc.yaml
replicationcontroller/nginx-demo created
[root@kubemaster k8s]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-demo-b5vwt 1/1 Running 0 15m 172.16.166.136 node1 <none> <none> nginx-demo-j8n7d 1/1 Running 0 15m 172.16.166.135 node1 <none> <none>
[root@kubemaster ~]# kubelet --version
Kubernetes v1.18.3
[root@kubemaster ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40",
GitTreeState:"clean", BuildDate:"2020-05-20T12:49:29Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64”}
[root@kubemaster ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
[root@kubemaster ~]# uname -r
4.18.0-193.el8.x86_64
kubernetes:用label让pod在指定的node上运行(kubernetes1.18.3)
标签:地址 coding bec 系统默认 arc 如何 情况下 div linux
原文地址:https://www.cnblogs.com/architectforest/p/13162362.html