This topic describes how to deploy a virtual node for a Kubernetes cluster by using the virtual node addon.

Background information

Virtual nodes are implemented by using Virtual Kubelet. Virtual nodes connect Kubernetes with Alibaba Cloud Elastic Container Instances (ECI), and provide Kubernetes clusters with a high level of elasticity. For more information about Virtual Kubelet, see How does Virtual Kubelet work?


Virtual nodes can help to enhance the elasticity of Kubernetes clusters. Specifically, virtual nodes based on Alibaba Cloud ECI can enhance the elasticity of clusters because they support GPU container instances, EIP addresses, and container instances of high specifications. Given the expansion capability provided by virtual nodes, you can easily manage multiple workloads for computing in a Kubernetes cluster.

In a cluster that contains virtual nodes, the pod in a physical node communicates with the ECI pod in the corresponding virtual node.

Note
  • The ECI pod in a virtual node is charged according to the specific amount of resources that you use. For information about ECI billing rules, see Billing overview.
  • ECS instances of the specifications range of 0.25 vCPU to 64 vCPU are supported. For more information, see Limits.

Prerequisites

A managed Kubernetes cluster is created. For more information, see Create a managed Kubernetes cluster.

Create a virtual node for a cluster Work node

  1. Log on to the Container Service console.
  2. In the left-side navigation pane under Container Service-Kubernetes, choose Store > App Catalog. Then, click ack-virtual-node.
  3. Click the Values tab, and then set these parameters.
    • ECI_VSWITCH: Set the VSwitch ID.
      To obtain the ID of the VSwitch that is associated with a Worker node, follow these steps:
      1. In the left-side navigation pane under Container Service-Kubernetes, choose Clusters > Nodes.
      2. Select the target cluster, and then click a Worker node.
      In the Configuration Information area, the VSwitch ID is displayed.
    • ECI_SECURITY_GROUP: Set the security group ID.
      To obtain the ID of the security group that is associated with a Worker node, follow these steps:
      1. In the left-side navigation pane under Container Service-Kubernetes, choose Clusters > Nodes.
      2. Select the target cluster, and then click a Worker node.
      3. In the left-side navigation pane, click Security Groups.
      On the Security Groups page, the security group ID is displayed.
    • ECI_ACCESS_KEY: Set the AccessKey.
    • ECI_SECRET_KEY: Set the SecretKey.
  4. In the Deploy area on the right of the page, select the target cluster, and then click DEPLOY.
    Note By default, the namespace is set to kube-system, and the release name is set to ack-virtual-node.


  5. In the left-side navigation pane under Container Service-Kubernetes, choose Clusters > Nodes to verify that a node named virtual-kubelet is displayed.

    You can use kubectl commands to view cluster nodes, and the status of Helm deployment. You can also use Helm to upgrade and manage the deployed ack-virtual-node. For more information, see Use kubectl commands in Cloud Shell to manage a Kubernetes cluster.

Create a pod in the virtual node

If a Kubernetes cluster contains a virtual node, you can create a pod in the virtual node. Then, the virtual kubelet will create a corresponding ECI pod. You can use one of the following three methods to create a pod for the virtual node:

  • Set nodeSelector and tolerations to create a pod.
    1. Log on to the Container Service console.
    2. In the left-side navigation pane under Container Service-Kubernetes, choose Applications > Deployments. Then, in the upper-right corner, click Create by Template.

    3. Select the target cluster and namespace, select an example template or customize a template, and then click DEPLOY.

      You can use the following template to customize a pod:

      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - image: nginx
          imagePullPolicy: Always
          name: nginx
        nodeSelector:
          type: virtual-kubelet
        tolerations:
        - key: virtual-kubelet.io/provider
          operator: Exists
  • Set nodeName to create a pod.
    1. In the left-side navigation pane under Container Service-Kubernetes, choose Applications > Deployments. Then, in the upper-right corner, click Create by Template.

    2. Select the target cluster and namespace, select an example template or customize a template, and then click DEPLOY.

      You can use the following template to customize a pod:

      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx
      spec:
        containers:
        - image: nginx
          imagePullPolicy: Always
          name: nginx
        nodeName: virtual-kubelet
  • Set a namespace tag to create a pod.
    1. Use kubectl on Cloud Shell to connect to the target Kubernetes cluster. For more information, see Use kubectl commands in Cloud Shell to manage a Kubernetes cluster.
    2. Run the following commands to create a pod:
      kubectl create ns vk
      kubectl label namespace vk virtual-node-affinity-injection=enabled
      kubectl -n vk run nginx --image nginx


In the left-side navigation pane under Container Service-Kubernetes, choose Applications > Pods to verify that the pod is created.