This sample includes two versions of a simple helloworld service that returns its version and instance (hostname) when called. It can be used as a test service when experimenting with version routing.
This service is also used to demonstrate canary deployments working in conjunction with autoscaling. See Canary deployments using Istio.
The following commands assume you have automatic sidecar injection enabled in your cluster. If not, you'll need to modify them to include manual sidecar injection.
To run both versions of the helloworld service, use the following command:
kubectl apply -f helloworld.yaml
Alternatively, you can run just one version at a time by first defining the service:
kubectl apply -f helloworld.yaml -l service=helloworld
and then deploying version v1, v2, or both:
kubectl apply -f helloworld.yaml -l version=v1 kubectl apply -f helloworld.yaml -l version=v2
For even more flexibility, there is also a script, gen-helloworld.sh
, that will generate YAML for the helloworld service. This script takes the following arguments:
Argument | Default | Description |
---|---|---|
--version | v1 | Specifies the version that will be returned by the helloworld service. |
--includeService | true | If true the service will be included in the YAML. |
--includeDeployment | true | If true the deployment will be included in the YAML. |
You can use this script to deploy a custom version:
./gen-helloworld.sh --version customversion | \ kubectl apply -f -
Apply the helloworld gateway configuration:
kubectl apply -f helloworld-gateway.yaml
Follow these instructions to set the INGRESS_HOST and INGRESS_PORT variables and then confirm the sample is running using curl:
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT curl http://$GATEWAY_URL/hello
Note that a Kubernetes Horizontal Pod Autoscaler only works if all containers in the pods request cpu. In this sample the deployment containers in helloworld.yaml
are configured with the request. The injected istio-proxy containers also include cpu requests, making the helloworld service ready for autoscaling.
Enable autoscaling on both versions of the service:
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 2 minutes and then check the number of replicas:
kubectl get hpa
If the autoscaler is functioning correctly, the REPLICAS
column should have a value > 1.
kubectl delete -f helloworld.yaml kubectl delete -f helloworld-gateway.yaml kubectl delete hpa helloworld-v1 helloworld-v2