Client Side Load Balancing

import helloWorld1YAML from ‘!!raw-loader!../../assets/howto/helloworld-1.yaml’; import helloWorldWsGroupsYAML from ‘!!raw-loader!../../assets/howto/helloworld-ws-groups.yaml’; import helloWorldIngressYAML from ‘!!raw-loader!../../assets/howto/helloworld-ingress.yaml’; import helloWorldGWYAML from ‘!!raw-loader!../../assets/howto/helloworld-gw.yaml’; import helloWorldClientLBYAML from ‘!!raw-loader!../../assets/howto/helloworld-client-lb.yaml’; import CodeBlock from ‘@theme/CodeBlock’;

The following YAML file has three objects - a Workspace for the application, a Gateway group so that you can configure the application ingress, and a Traffic group that will allow you to configure the canary release process.


Store the file as helloworld-ws-groups.yaml, and apply with tctl:

tctl apply -f helloworld-ws-groups.yaml

To deploy your application, start by creating the namespace and enable the Istio sidecar injection.

kubectl create namespace helloworld
kubectl label namespace helloworld istio-injection=enabled

Then deploy your application.


Store as helloworld-1.yaml, and apply with kubectl:

kubectl apply -f helloworld-1.yaml

Note that you’re deploying 3 replicas for this deployment.

In this example, you’re going to expose the application using simple TLS at the gateway. You’ll need to provide it with a TLS certificate stored in a Kubernetes secret.

kubectl create secret tls -n helloworld helloworld-cert \
    --cert /path/to/some/helloworld-cert.pem \
    --key /path/to/some/helloworld-key.pem

Now you can deploy your ingress gateway.


Save as helloworld-ingress.yaml, and apply with kubectl:

kubectl apply -f helloworld-ingress.yaml

The TSB data plane operator in the cluster will pick up this configuration and deploy the gateway’s resources in your application namespace. Finally, configure the gateway so that it routes traffic to your application.


Save as helloworld-gw.yaml, and apply with tctl:

tctl apply -f helloworld-gw.yaml

You can check that your application is reachable by opening your web browser and directing it to the gateway service IP or domain name (depending on your configuration).

At this point, your application will load balance using Round Robin by default. Now, configure client-side load balancing and use the source IP.


Save as helloworld-client-lb.yaml, and apply with tctl:

tctl apply -f helloworld-client-lb.yaml

Now, the same pod is being used as a backend for all our requests coming from the same IP.

In this example you have used the source IP, but there are other methods allowed too; using the header of an HTTP request, or configuring an HTTP cookie.