Graceful Shutdown

Ref


HPA

Build

sh script.sh {image_repo} {image_name}

For example:

sh script.sh qoosdd89382 graceful

Deploy

Edit /deploy/deployment.yaml by changing image: field to your image repository, then run:

kubectl apply -f deploy/deployment.yaml
kubectl apply -f deploy/hpa.yaml
kubectl apply -f deploy/service.yaml

Deployment Availability Test

kubectl port-forward svc/graceful 8089:8089

Access localhost:8089/hpa on your host, you will get a message like success.

Test For HPA

kubectl run curl --image=alpine/curl --rm -it -- sh 

Then run command below in the pod:

while true; do curl graceful:8089/hpa; done

Watch

Highly recommend to install watch tool. In Mac OSX:

brew install watch

After installing, run:

watch kubectl top pod

Notice

You need to check the version of HPA from your Kubernetes cluster:

$ kubectl api-versions | grep autoscaling                                                                                                                                                            ─╯

autoscaling/v1
autoscaling/v2
autoscaling/v2beta2

HorizontalPodAutoscaler in version "v1" cannot be handled as a HorizontalPodAutoscaler:

strict decoding error: unknown field "spec.behavior", unknown field "spec.metrics".