Configuring Specified Node Scheduling (nodeSelector)
To select a node for scheduling in Kubernetes, simply configure the nodeSelector field in the workload. This field allows you to configure the label of the desired node to be scheduled. Kubernetes schedules pods only to nodes with specified labels.
Step 1: Adding a Label to a Node
- Log in to the CCE console and click the cluster name to access the cluster console.
- In the navigation pane, choose Nodes. On the displayed page, click the Nodes tab, select the target node and click Labels and Taints in the upper left corner.
- In the displayed dialog box, click Add operation under Batch Operation, and then choose Add/Update or Delete.
Enter the key and value of the label to be added or deleted, and click OK.
For example, the key is deploy_qa and the value is true, indicating that the node is used to deploy the QA (test) environment.
Figure 1 Adding a node label
- After the label is added, check the added label in node data.
Step 2: Creating a Workload Scheduled to a Specified Node
- Use kubectl to access the cluster. For details, see Connecting to a Cluster Using kubectl.
- Create a YAML file named nginx.yaml. The file name can be customized.
Configure nodeSelector for the workload.
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: nodeSelector: deploy_qa: "true" containers: - image: nginx:latest imagePullPolicy: IfNotPresent name: nginx imagePullSecrets: - name: default-secret
For example, if the key is deploy_qa and the value is true, the pod will be scheduled to the node with the deploy_qa=true label.
- Create a workload.
kubectl apply -f nginx.yaml
Step 3: Verifying the Scheduling
- Log in to the CCE console and click the cluster name to access the cluster console.
- In the navigation pane, choose Workloads.
- Click the workload name to enter its details page. In the pod list, verify that all pods are running on the target node, which is labeled with deploy_qa=true.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot