Let’s deploy our workload, in our examples we will a deploy simple apache deployment and busybox deployment just to simulate the behaviour of Ocean under load.
Create a file autoscale-test.yaml
with the following content
apiVersion: v1
kind: Namespace
metadata:
name: autoscale-test
labels:
name: autoscale-test
spot.io/inject-aks-spot-toleration: "true"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-apache
namespace: autoscale-test
spec:
selector:
matchLabels:
run: php-apache
replicas: 1
template:
metadata:
labels:
run: php-apache
spec:
containers:
- name: php-apache
image: k8s.gcr.io/hpa-example
ports:
- containerPort: 80
resources:
limits:
cpu: 500m
requests:
cpu: 200m
nodeSelector:
env: ocean-workshop
example: "1"
---
apiVersion: v1
kind: Service
metadata:
name: php-apache
namespace: autoscale-test
labels:
run: php-apache
spec:
ports:
- port: 80
selector:
run: php-apache
As you can see we added the nodeSelector so this pod will use the VNG (Example-1) we created in previous lab.
nodeSelector:
env: ocean-workshop
example: "1"
Apply the file using kubectl, run kubectl apply -f autoscale-test.yaml
➜ kubectl apply -f autoscale-test.yaml
namespace/autoscale-test created
deployment.apps/php-apache created
service/php-apache created
Configure HPA (horizontal pod autoscaler) for this deployment so it can scale depending on the load.
Run kubectl autoscale deployment php-apache --cpu-percent=40 --min=1 --max=900 -n autoscale-test
➜ kubectl autoscale deployment php-apache --cpu-percent=40 --min=1 --max=900 -n autoscale-test
horizontalpodautoscaler.autoscaling/php-apache autoscaled
Check the current configuration for HPA.
Run kubectl get hpa -n autoscale-test
➜ kubectl get hpa -n autoscale-test
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
php-apache Deployment/php-apache <unknown>/40% 1 900 1 5m46s
Let’s create the Busybox deployment and deploy it.
Create a file infinite-calls.yaml
with the following content
apiVersion: apps/v1
kind: Deployment
metadata:
name: infinite-calls
namespace: autoscale-test
labels:
app: infinite-calls
spec:
replicas: 40
selector:
matchLabels:
app: infinite-calls
template:
metadata:
name: infinite-calls
labels:
app: infinite-calls
spec:
containers:
- name: infinite-calls
image: busybox
command:
- /bin/sh
- -c
- "while true; do wget -q -O- http://php-apache; done"
Apply the file using kubectl, run kubectl apply -f infinite-calls.yaml
➜ kubectl apply -f infinite-calls.yaml
deployment.apps/infinite-calls created
List the pods to make sure they all are up and running, run kubectl get pod -n autoscale-test
➜ kubectl get pod -n autoscale-test
NAME READY STATUS RESTARTS AGE
infinite-calls-6955dbf57f-2cmrp 1/1 Running 0 42s
infinite-calls-6955dbf57f-2s7jx 1/1 Running 0 42s
infinite-calls-6955dbf57f-4pmrh 1/1 Running 0 42s
infinite-calls-6955dbf57f-4wmzn 1/1 Running 0 42s
infinite-calls-6955dbf57f-5pl6j 1/1 Running 0 42s
infinite-calls-6955dbf57f-5rr96 1/1 Running 0 42s
infinite-calls-6955dbf57f-69dsg 1/1 Running 0 42s
infinite-calls-6955dbf57f-6r2lb 1/1 Running 0 42s
infinite-calls-6955dbf57f-6xx4p 1/1 Running 0 42s
infinite-calls-6955dbf57f-7tchk 1/1 Running 0 42s
infinite-calls-6955dbf57f-7tlqn 1/1 Running 0 42s
infinite-calls-6955dbf57f-8598b 1/1 Running 0 42s
infinite-calls-6955dbf57f-9j86h 1/1 Running 0 42s
infinite-calls-6955dbf57f-c2q59 1/1 Running 0 42s
infinite-calls-6955dbf57f-d67jf 1/1 Running 0 42s
infinite-calls-6955dbf57f-dd2zq 1/1 Running 0 42s
infinite-calls-6955dbf57f-dkkxd 1/1 Running 0 42s
infinite-calls-6955dbf57f-fckmf 1/1 Running 0 42s
infinite-calls-6955dbf57f-gkrxx 1/1 Running 0 42s
infinite-calls-6955dbf57f-gvs8l 1/1 Running 0 42s
infinite-calls-6955dbf57f-hrz29 1/1 Running 0 42s
infinite-calls-6955dbf57f-l2fgg 1/1 Running 0 42s
infinite-calls-6955dbf57f-l55sr 1/1 Running 0 42s
infinite-calls-6955dbf57f-lqpz2 1/1 Running 0 42s
infinite-calls-6955dbf57f-mpnjw 1/1 Running 0 42s
infinite-calls-6955dbf57f-n5p87 1/1 Running 0 42s
infinite-calls-6955dbf57f-rnkxl 1/1 Running 0 42s
infinite-calls-6955dbf57f-sfl6j 1/1 Running 0 42s
infinite-calls-6955dbf57f-slj2f 1/1 Running 0 42s
infinite-calls-6955dbf57f-srxpz 1/1 Running 0 42s
infinite-calls-6955dbf57f-tdxpm 1/1 Running 0 42s
infinite-calls-6955dbf57f-tkv9f 1/1 Running 0 42s
infinite-calls-6955dbf57f-tnvnk 1/1 Running 0 42s
infinite-calls-6955dbf57f-vf2l7 1/1 Running 0 42s
infinite-calls-6955dbf57f-xf5p9 1/1 Running 0 42s
infinite-calls-6955dbf57f-xf7nr 1/1 Running 0 42s
infinite-calls-6955dbf57f-xmjcg 1/1 Running 0 42s
infinite-calls-6955dbf57f-xnj7m 1/1 Running 0 42s
infinite-calls-6955dbf57f-xxctz 1/1 Running 0 42s
infinite-calls-6955dbf57f-zv2xx 1/1 Running 0 42s
php-apache-6ffdc8964-6wlfb 1/1 Running 0 17m
Give the Busyboxes some time to generate the load, wait around 5-10 minutes.
To make sure that busybox working properly use the following command ( replace the pod name )
kubectl exec -it infinite-calls-6955dbf57f-zv2xx sh -n autoscale-test
/ #
/ # ps
PID USER TIME COMMAND
1 root 0:00 /bin/sh -c while true; do wget -q -O- http://php-apache; done
496 root 0:00 sh
502 root 0:00 wget -q -O- http://php-apache
503 root 0:00 ps
/ #