Use label to control the position of pod - 5 minutes a day to play with Docker container technology (128)

By default, Scheduler will schedule Pods to all available Nodes. However, in some cases, we want to deploy Pods to specified Nodes, such as deploying Pods with a large amount of disk I/O to Nodes configured with SSDs; or Pods require GPUs and need to run on nodes configured with GPUs.

Kubernetes implements this function through labels.

Label is a key-value pair. Labels can be set for various resources, and various custom attributes can be added flexibly. For example, execute the following command to mark k8s-node1 as the node configured with SSD.

kubectl label node k8s-node1 disktype=ssd

Then by  kubectl get node --show-labels looking at the label of the node.

disktype=ssd It has been successfully added to k8s-node1, except  disktypethat Node has several labels maintained by Kubernetes itself.

With  disktype this custom label, the next step is to specify the Pod to be deployed to k8s-node1. Edit nginx.yml:

 Deploy this Pod to a   Node with a label spec by  specifying it in the Pod template  .nodeSelectordisktype=ssd

Deploy the Deployment and see where the Pod is running:

All 6 replicas are running on k8s-node1, as we expected.

To remove the label  disktype, execute the following command:

kubectl label node k8s-node1 disktype-

 - i.e. delete.

However, the Pod will not be redeployed at this time, and it will still run on k8s-node1.

Unless the settings are removed in nginx.yml  nodeSelector and then via  kubectl apply redeploy.

Kubernetes deletes the previous Pod and schedules and runs the new Pod.

Deployment related operations are discussed here. In the next section, we will learn about DaemonSet.

books:

1. "Play with Docker container technology in 5 minutes a day"
https://item.jd.com/16936307278.html

2. "Play with OpenStack in 5 minutes a day"
https://item.jd.com/12086376.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325023117&siteId=291194637