Spot hello world
Easy-to-do tutorial to get started in no time with Spot node pool!
DEPRECATED
Prerequisites
To run this onboarding tutorial, we should first have:
- a k8saas cluster deployed with Spot node pool
To ask and set up your own cluster, look at the section Getting Started.
And downloaded the following files:
Tutorial
The application is two website, displaying a welcome page on port 80 deployed on spot node pool.
Get your credentials
The cluster name and the resource group name are the same within k8saas.
az aks get-credentials --name "$K8SAAS_RESOURCE_NAME" --resource-group "$K8SAAS_RESOURCE_NAME"
kubelogin convert-kubeconfig -l azurecli
Deploy the application
Deploy the application, composed of :
- a kubernetes Deployment object: which spin up the application pod (container) on the spot node;
- a kubernetes Service object: which exposes the pod internally.
Using the following commands:
# this start a hello world pod on a spot node
kubectl apply -f aks-helloworld-one-spot.yaml --namespace customer-namespaces
kubectl apply -f aks-helloworld-two-spot.yaml --namespace customer-namespaces
These will schedule a pod to run on a spot node by adding a toleration and an affinity to the pod's deployment manifest file. When the toleration and node affinity correspond with the taint and label applied to your spot nodes, the pod is scheduled on these nodes.
The nodes in a spot node pool are assigned a taint that equals kubernetes.azure.com/scalesetpriority=spot:NoSchedule
and a label that equals kubernetes.azure.com/scalesetpriority=spot
. Use the information in this key-value pair in the tolerations
and affinity
section of your workloads YAML manifest file. As shown in the Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: aks-helloworld-one
spec:
replicas: 1
selector:
matchLabels:
app: aks-helloworld-one
template:
metadata:
labels:
app: aks-helloworld-one
spec:
containers:
- name: aks-helloworld-one
image: mcr.microsoft.com/azuredocs/aks-helloworld:v1
ports:
- containerPort: 80
env:
- name: TITLE
value: "Welcome to Azure Kubernetes Service (AKS)"
tolerations:
- key: "kubernetes.azure.com/scalesetpriority"
operator: "Equal"
value: "spot"
effect: "NoSchedule"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "kubernetes.azure.com/scalesetpriority"
operator: In
values:
- "spot"
# look at your pods
kubectl get pods -n customer-namespaces -o wide
# NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
# aks-helloworld-one-566b8df5cd-2c82z 1/1 Running 0 41h xx.xx.xx.xx aks-spotpool01-24191796-vmss000002 <none> <none>
# aks-helloworld-two-5b79f5dffd-v86p5 1/1 Running 0 41h xx.xx.xx.xx aks-spotpool01-24191796-vmss000002 <none> <none>
Expose the application
Both applications are now running on your Kubernetes cluster. To route traffic to each application, create a Kubernetes ingress resource. The ingress resource configures the rules that route traffic to one of the two applications.
In the following example, traffic to EXTERNAL_IP/hello-world-one is routed to the service named aks-helloworld-one
. Traffic to EXTERNAL_IP/hello-world-two is routed to the aks-helloworld-two
service. Traffic to EXTERNAL_IP/static is routed to the service named aks-helloworld-one
for static assets.
Use the command:
kubectl apply -f hello-world-ingress-spot.yaml --namespace customer-namespaces
Get the Public Ip address with the following command:
kubectl get ingress -n customer-namespaces
# NAME CLASS HOSTS ADDRESS PORTS AGE
# hello-world-ingress nginx * 20.242.248.32 80 41h
# hello-world-ingress-static nginx * 20.242.248.32 80 41h
Now, open a browser and consult your first application: http://<IP_ADDRESS>
or in a shell:
curl -k https://<IP_ADDRESS>
Now, open a browser and consult your second application: http://<IP_ADDRESS>/hello-world-two
or in a shell:
curl -k https://<IP_ADDRESS>/hello-world-two
Remove your test
kubectl delete -f aks-helloworld-one-spot.yaml --namespace customer-namespaces
kubectl delete -f aks-helloworld-two-spot.yaml --namespace customer-namespaces
kubectl delete -f hello-world-ingress-spot.yaml --namespace customer-namespaces