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.
apiVersion: v1
kind: Namespace
metadata:
name: autoscale-test
labels:
name: autoscale-test
---
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"
Navigate back to your cloud9 IDE and run the following
kubectl apply -f /home/ec2-user/environment/spot-workshop-template/autoscale-test.yaml
Your output should match the following:
➜ kubectl apply -f /home/ec2-user/environment/spot-workshop-template/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 the following command in Cloud9 IDE ``
kubectl autoscale deployment php-apache --cpu-percent=40 --min=1 --max=100 -n autoscale-test
Your output should mirror the following:
➜ kubectl autoscale deployment php-apache --cpu-percent=40 --min=1 --max=100 -n autoscale-test
horizontalpodautoscaler.autoscaling/php-apache autoscaled
Check the current configuration for HPA by running the following command:
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 100 1 5m46s
Now we will create the Busybox deployment shown below.
Apply the file using kubectl, run
kubectl apply -f /home/ec2-user/environment/spot-workshop-template/infinite-calls.yaml
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"
Your output should mirror the following:
➜ kubectl apply -f infinite-calls.yaml
deployment.apps/infinite-calls created
List the pods to make sure they all are up and running by running the following command:
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.