This sample runs two versions of a simple helloworld service that return their version and instance (hostname) when called. It's used to demonstrate canary deployments working in conjunction with autoscaling. See Canary deployments using Istio.
If you don't have automatic sidecar injection set in your cluster you will need to manually inject it to the services:
istioctl kube-inject -f helloworld.yaml -o helloworld-istio.yaml
Note that Kubernetes Horizontal Pod Autoscaler
only work if all containers in the pods requests cpu. In this sample the deployment
containers within the helloworld.yaml
are pre-defined with the request. The (manually/automatically)
injected istio-proxy containers also have the requests cpu therefore making the helloworld
ready for autoscaling.
Now create the deployment using the updated yaml file and create the gateway configuration:
kubectl create -f helloworld-istio.yaml
kubectl create -f helloworld-gateway.yaml
Follow the instructions to set the INGRESS_HOST and INGRESS_PORT variables then confirm it's running using curl.
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
curl http://$GATEWAY_URL/hello
Enable autoscale on both services:
kubectl autoscale deployment helloworld-v1 --cpu-percent=50 --min=1 --max=10
kubectl autoscale deployment helloworld-v2 --cpu-percent=50 --min=1 --max=10
kubectl get hpa
./loadgen.sh &
./loadgen.sh & # run it twice to generate lots of load
Wait for about 2min and check the number of replicas:
kubectl get hpa
If autoscaler is functioning correctly the REPLICAS
column should have a
value > 1.
kubectl delete -f helloworld-istio.yaml
kubectl delete -f helloworld-gateway.yaml
kubectl delete hpa helloworld-v1 helloworld-v2