How to Use Virtual Node Addon to Improve Cluster Elasticity

What Are Virtual Nodes?

Use Cases

Installing the ack-virtual-node Plug-in

Creating a Pod Based on a Virtual Node

1. Set nodeSelector and Tolerations for the 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

2. Set nodeName for the Pod

apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
nodeName: virtual-kubelet

3. Configure the Tag for the Namespace to Specify That All Pods in the Namespace are Scheduled to Virtual Nodes.

kubectl create ns vk
kubectl label namespace vk virtual-node-affinity-injection=enabled
kubectl -n vk run nginx --image nginx
# kubectl -n vk apply -f https://raw.githubusercontent.com/AliyunContainerService/serverless-k8s-examples/master/ingress/ingress-cafe-demo.yaml
deployment "coffee" created
service "coffee-svc" created
deployment "tea" created
service "tea-svc" created
ingress "cafe-ingress" created
# kubectl -n vk get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
coffee-56668d6f78-7mdvc 1/1 Running 0 2m 192.168.1.170 virtual-kubelet
coffee-56668d6f78-tpslg 1/1 Running 0 2m 192.168.1.169 virtual-kubelet
tea-85f8bf86fd-5fl2v 1/1 Running 0 2m 192.168.1.172 virtual-kubelet
tea-85f8bf86fd-8n9n8 1/1 Running 0 2m 192.168.1.171 virtual-kubelet
tea-85f8bf86fd-jv7kj 1/1 Running 0 2m 192.168.1.173 virtual-kubelet
# kubectl -n vk get ing
NAME HOSTS ADDRESS PORTS AGE
cafe-ingress cafe.example.com 120.55.8.82 80 2m
# curl -H "Host:cafe.example.com" 120.55.8.82/tea
Server address: 192.168.1.173:80
Server name: vk-tea-85f8bf86fd-jv7kj
Date: 13/May/2019:05:54:32 +0000
URI: /tea
Request ID: 84d2afa2d3a74d7af38f94de21d11d37
# curl -H "Host:cafe.example.com" 120.55.8.82/coffee
Server address: 192.168.1.169:80
Server name: vk-coffee-56668d6f78-tpslg
Date: 13/May/2019:05:54:36 +0000
URI: /coffee
Request ID: 280df5e9f29d22d8174540f8dfe77861

Original Source

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store