This topic describes how to run a job by using a virtual node. You can use this method during peak hours with no need for creating new nodes for your cluster.
When you use a virtual node, your Kubernetes cluster can provide greater computing capability and allow you to create pods as needed.
For example, you have a Kubernetes cluster with one managed Master node and two Worker nodes, and the specifications of each Worker node is 4 CPUs and 8 GB. Therefore, the specifications of the managed Kubernetes cluster is 8 CPUs and 16 GB.
To run an offline job with 16 CPUs and 32 GB to process data, you can schedule the job to a virtual node to save computing resources for nodes of the cluster.
- A managed Kubernetes cluster is created. For more information, see Create a cluster of ACK Managed Edition.
- A virtual node is deployed in the managed Kubernetes cluster. For more information, see Virtual nodes.
- The tag virtual-node-affinity-injection: enabled is added to the target namespace. For more information, see Set a namespace tag to create a pod.
- Connect to a Kubernetes cluster by using kubectl. For more information, see Use kubectl to connect to a cluster.
- Copy and paste the following codes to job.yaml and run the
kubectl -n vk apply -f job.yamlcommand to deploy a job.
kind: Job metadata: name: pi spec: template: spec: containers: - name: pi image: perl command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] resources: requests: cpu: 16 memory: 32Gi restartPolicy: Never backoffLimit: 4
- Run the following command to view the pod running status.
kubectl -n vk get pod -a
NAME READY STATUS RESTARTS AGE pi-7cmwv 0/1 Completed 0 2m
kubectl -n vk describe pod
Name: pi-7cmwv Namespace: vk Priority: 0 PriorityClassName: <none> Node: virtual-kubelet/ ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 3m default-scheduler Successfully assigned vk/pi-7cmwv to virtual-kubelet Normal SuccessfulMountVolume 2m kubelet, eci MountVolume.SetUp succeeded for volume "default-token-b2tff" Normal Pulling 2m kubelet, eci pulling image "perl" Normal Pulled 2m kubelet, eci Successfully pulled image "perl" Normal Created 2m kubelet, eci Created container Normal Started 2m kubelet, eci Started containerNote The pod on a virtual node is charged according to the specific amount of resources that you use.