All Products
Search
Document Center

Container Service for Kubernetes:Schedule application pods to the specified node

Last Updated:May 16, 2024

You can configure node labels and a node selector to schedule application pods to the specified node.

Prerequisites

Step 1: Configure node labels

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. In the left-side navigation pane of the details page, choose Nodes > Nodes.

  3. On the Nodes page, click Manage Labels and Taints in the upper-right corner to go to the Manage Labels and Taints page.

  4. On the Labels tab, select the node that you want to use and click Add Label.

  5. In the Add dialog box, specify Name and Value of the label and click OK.

    • Name: The label key can contain letters, digits, underscores (_), hyphens (-), and periods (.). It must start and end with a letter or digit. In this example, the label key is pod.

    • Value: The label value can be an empty string or contain letters, digits, underscores (_), hyphens (-), and periods (.). It must start and end with a letter or digit. In this example, the label value is nginx.

Step 2: Schedule application pods to the specified node

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. In the left-side navigation pane of the details page, choose Workloads > Deployments.

  3. Click View in YAML in the Actions column of the Deployment that you want to manage and configure a node selector. In this topic, the Deployment named nginx-deployment-basic is used as an example.

    apiVersion: apps/v1 
    kind: Deployment
    metadata:
      name: nginx-deployment-basic
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          nodeSelector:
            pod: nginx      #Specify the label of the node that you added to ensure that the application pods run only on this node. Specify the actual label that you added. 
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80
  4. Click Update. The system prompts the deployment information.

Verify the configuration

Click the name of the Deployment to go to the details page and click the Pods tab. The tab shows that the application pods are scheduled to the node xxx.xxx.33.88. The node has the pod: nginx label. 20231228183946.jpg

References

  • For more information about nodeSelector, see Assigning Pods to Nodes.

  • When you release or scale out an application, you can configure a ResourcePolicy to specify the priorities of different node types to which application pods are scheduled. When the system scales in application pods, pods are removed from nodes based on the priorities of the nodes in ascending order. For more information, see Configure priority-based resource scheduling.