kubernetes:用label让pod在指定的node上运行(kubernetes1.18.3)
2021-02-03 02:15
标签:地址 coding bec 系统默认 arc 如何 情况下 div linux 说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest 对应的源码可以访问这里获取: https://github.com/liuhongdi/ 说明:作者:刘宏缔 邮箱: 371125307@qq.com 说明:各node的label都是系统默认的,还没有我们手动添加的 添加 查看效果: 删除 kubernetes:用label让pod在指定的node上运行(kubernetes1.18.3) 标签:地址 coding bec 系统默认 arc 如何 情况下 div linux 原文地址:https://www.cnblogs.com/architectforest/p/13162362.html一,为什么要为node指定label?
二,用label让pod在指定的node上运行:
[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
kubectl label nodes
[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
[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
kubectl label nodes
[root@kubemaster k8s]# kubectl label nodes node1 apptype-
node/node1 labeled
三,如何把Pod 部署到指定label的 Node:
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
[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
四,查看kubernetes的版本
[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”}五,查看linux的版本
[root@kubemaster ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
[root@kubemaster ~]# uname -r
4.18.0-193.el8.x86_64
下一篇:本地项目文件上传到git
文章标题:kubernetes:用label让pod在指定的node上运行(kubernetes1.18.3)
文章链接:http://soscw.com/index.php/essay/50215.html