1.在worker节点 (computer),配置SSD

# kubectl label node computer disktype=ssd
node/computer labeled

# kubectl get  node --show-labels
NAME         STATUS   ROLES    AGE   VERSION   LABELS
computer     Ready    worker   23d   v1.17.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=computer,kubernetes.io/os=linux,node-role.kubernetes.io/worker=worker
controller   Ready    master   23d   v1.17.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=controller,kubernetes.io/os=linux,node-role.kubernetes.io/master=
storage      Ready    worker   23d   v1.17.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=storage,kubernetes.io/os=linux,node-role.kubernetes.io/worker=worker2

2.在yaml格式指定将Pod部署到computer节点(worker)上

# vi nginx.yml 

apiVersion: apps/v1
kind: Deployment
metadata:
 name: nginx
spec:
 selector:
  matchLabels:
   app: web_server
 replicas: 3
 template:
  metadata:
   labels:
    app: web_server
  spec:
   containers:
   - name: nginx
     image: nginx:1.7.9
     ports:
     - containerPort: 80
   nodeSelector:
    disktype: ssd

3.部署yaml格式编辑的内容

# kubectl apply -f nginx.yml 
deployment.apps/nginx created

# kubectl get pod -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
nginx-7c6c55dbc5-9s8b8   1/1     Running   0          90s   10.244.1.15   computer   <none>           <none>
nginx-7c6c55dbc5-hc7hx   1/1     Running   0          90s   10.244.1.16   computer   <none>           <none>
nginx-7c6c55dbc5-tqwgc   1/1     Running   0          90s   10.244.1.14   computer   <none>           <none>

4.删除label disktype属性

# kubectl label node computer disktype-
node/computer labeled

# kubectl get node --show-labels
NAME         STATUS   ROLES    AGE   VERSION   LABELS
computer     Ready    worker   23d   v1.17.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=computer,kubernetes.io/os=linux,node-role.kubernetes.io/worker=worker
controller   Ready    master   23d   v1.17.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=controller,kubernetes.io/os=linux,node-role.kubernetes.io/master=
storage      Ready    worker   23d   v1.17.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=storage,kubernetes.io/os=linux,node-role.kubernetes.io/worker=worker2

5.需要在nginx.yml中删除nodeSelector设置,然后通过kubectl apply重新部署

# vi nginx.yml 

apiVersion: apps/v1
kind: Deployment
metadata:
 name: nginx
spec:
 selector:
  matchLabels:
   app: web_server
 replicas: 3
 template:
  metadata:
   labels:
    app: web_server
  spec:
   containers:
   - name: nginx
     image: nginx:1.7.9
     ports:
     - containerPort: 80

# kubectl apply -f nginx.yml 
deployment.apps/nginx configured

# kubectl get pod -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
nginx-7f768d8977-b8bpz   1/1     Running   0          30s   10.244.2.7    storage    <none>           <none>
nginx-7f768d8977-jsg8m   1/1     Running   0          27s   10.244.1.18   computer   <none>           <none>
nginx-7f768d8977-tdd29   1/1     Running   0          32s   10.244.1.17   computer   <none>           <none>

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐