Deploying Istio on a Kubernetes Kapsule with ProxyProtocol v2 support
- kubernetes
- load-balancer
- proxy-protocol
- istio
Istio is an open source service mesh that lets you run distributed, microservices-based apps anywhere. It helps you manage and connect the different microservices in your Scaleway Kubernetes cluster, making it easier to build and maintain complex applications.
This tutorial describes the steps required to deploy Istio on a Scaleway Kubernetes Kapsule cluster, and configure it to support Proxy Protocol v2. This enables connection information from a client (e.g. their IP address) to be passed through the cluster’s Load Balancer onto the target pod or service, via the Istio service mesh.
Before you startLink to this anchor
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- A Kubernetes Kapsule cluster with a Scaleway Load Balancer service
- Set up kubetcl and Helm
Install Istio with HelmLink to this anchor
-
Add the Istio Helm repository:
helm repo add istio https://istio-release.storage.googleapis.com/chartshelm repo update -
Create a Kubernetes namespace for Istio:
kubectl create namespace istio-system -
Install the Istio base and control plane into the previously created namesapce:
helm install istio-base istio/base -n istio-systemhelm install istiod istio/istiod -n istio-system --wait -
Install the Istio ingress Gateway:
helm install istio-ingressgateway istio/gateway -n istio-system --wait
Install a test application (httpbin)Link to this anchor
Deploy a simple application to test how Istio works with a Load Balancer.
In this tutorial we use httpbin
as test application.
-
Create and label a new namespace for the test application:
kubectl create namespace test-appkubectl label namespace test-app istio-injection=enabled -
Apply the following configuration using
kubectl
:kubectl apply -n test-app -f - <<EOFapiVersion: apps/v1kind: Deploymentmetadata:name: httpbinspec:replicas: 1selector:matchLabels:app: httpbintemplate:metadata:labels:app: httpbinspec:containers:- name: httpbinimage: kennethreitz/httpbinports:- containerPort: 80---apiVersion: v1kind: Servicemetadata:name: httpbinspec:selector:app: httpbinports:- name: httpport: 80targetPort: 80EOF
Creating an Istio Gateway and a VirtualServiceLink to this anchor
Define a Gateway and a VirtualService to expose the application via the Istio IngressGateway.
- Run the following command to apply the configuration using
kubectl
:
kubectl apply -n test-app -f - <<EOFapiVersion: networking.istio.io/v1beta1kind: Gatewaymetadata:name: httpbin-gatewaynamespace: test-appspec:selector:istio: ingressgatewayservers:- port:number: 80name: httpprotocol: HTTPhosts:- "*"---# virtualservice.yamlapiVersion: networking.istio.io/v1beta1kind: VirtualServicemetadata:name: httpbinnamespace: test-appspec:hosts:- "*"gateways:- httpbin-gatewayhttp:- route:- destination:host: httpbinport:number: 80EOF
-
Run the following command to retrieve the IP of your Load Balancer and save it in the
$LB_IP
variable:export LB_IP=$(kubectl get svc -n istio-system istio-ingressgateway -ojsonpath='{.status.loadBalancer.ingress[0].ip}')echo $LB_IP -
Run the following command to do a test before proxy forward is configured:
curl -v http://$LB_IP/getYou will get an output similar to the following example:
curl -vhttp://$LB_IP/get* Trying 51.159.112.157:80...* Connected to 51.159.112.157 (51.159.112.157) port 80> GET /get HTTP/1.1> Host: 51.159.112.157> User-Agent: curl/8.7.1> Accept: */*>* Request completely sent off< HTTP/1.1 200 OK< server: istio-envoy< date: Mon, 24 Feb 2025 09:06:45 GMT< content-type: application/json< content-length: 491< access-control-allow-origin: *< access-control-allow-credentials: true< x-envoy-upstream-service-time: 19<{"args": {},"headers": {"Accept": "*/*","Host": "51.159.112.157","User-Agent": "curl/8.7.1","X-Envoy-Attempt-Count": "1","X-Envoy-Internal": "true","X-Forwarded-Client-Cert": "By=spiffe://cluster.local/ns/testapp/sa/default;Hash=ddf3ba6fee32a74f9a83efd752df7960c9f3139fa1fe979370becddad3def062;Subject=\"\";URI=spiffe://cluster.local/ns/istiosystem/sa/istio-ingressgateway"},"origin": "172.16.16.5","url": "http://51.159.112.157/get"}* Connection #0 to host 51.159.112.157 left intact
Configuring the Scaleway Load BalancerLink to this anchor
When you deploy a LoadBalancer service in Kubernetes, Scaleway automatically creates a Load Balancer and associates it with your service. You now need to activate Proxy Protocol V2
for this Load Balancer.
Modify the istio-ingressgateway
service to add the necessary annotations:
kubectl annotate -n istio-system services istio-ingressgateway \service.beta.kubernetes.io/scw-loadbalancer-proxy-protocol-v2=truekubectl annotate -n istio-system services istio-ingressgateway \service.beta.kubernetes.io/scw-loadbalancer-use-hostname=true
Configure Proxy protocol and the X-Forwarded-For header to retrieve the source IPLink to this anchor
-
Create an
EnvoyFilter
to enable Proxy Protocol support:kubectl apply -f - <<EOFapiVersion: networking.istio.io/v1alpha3kind: EnvoyFiltermetadata:name: proxy-protocolnamespace: istio-systemspec:workloadSelector:labels:istio: ingressgatewayconfigPatches:- applyTo: LISTENERpatch:operation: MERGEvalue:listener_filters:- name: envoy.filters.listener.proxy_protocoltyped_config:'@type': type.googleapis.com/envoy.extensions.filters.listener.proxy_protocol.v3.ProxyProtocol- name: envoy.filters.listener.tls_inspectortyped_config:'@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspectorEOF -
Run the
curl -v http://$LB_IP/get
command again and watch the output. You will get an output similar to the following example:curl -v http://$LB_IP/get* Trying 51.159.112.157:80...* Connected to 51.159.112.157 (51.159.112.157) port 80> GET /get HTTP/1.1> Host: 51.159.112.157> User-Agent: curl/8.7.1> Accept: */*>* Request completely sent off< HTTP/1.1 200 OK< server: istio-envoy< date: Mon, 24 Feb 2025 09:11:46 GMT< content-type: application/json< content-length: 510< access-control-allow-origin: *< access-control-allow-credentials: true< x-envoy-upstream-service-time: 4<{"args": {},"headers": {"Accept": "*/*","Host": "51.159.112.157","User-Agent": "curl/8.7.1","X-Envoy-Attempt-Count": "1","X-Envoy-External-Address": "62.210.16.37","X-Forwarded-Client-Cert": "By=spiffe://cluster.local/ns/test-app/sa/default;Hash=ddf3ba6fee32a74f9a83efd752df7960c9f3139fa1fe979370becddad3def062;Subject=\"\";URI=spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway"},"origin": "62.210.16.37","url": "http://51.159.112.157/get"}* Connection #0 to host 51.159.112.157 left intact -
Configure Istio using
kubectl
to ensure that the source IP is correctly transmitted via theX-Forwarded-For
header.kubectl apply -f - <<EOFapiVersion: networking.istio.io/v1alpha3kind: EnvoyFiltermetadata:name: ingressgateway-settingsnamespace: istio-systemspec:configPatches:- applyTo: NETWORK_FILTERmatch:listener:filterChain:filter:name: envoy.filters.network.http_connection_managerpatch:operation: MERGEvalue:name: envoy.filters.network.http_connection_managertyped_config:"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManagerskip_xff_append: falseuse_remote_address: truexff_num_trusted_hops: 1EOFYou will get an output similar to the following one, after you have configured proxy forward and
X-Forward-For
curl -v http://$LB_IP/get* Trying 51.159.112.157:80...* Connected to 51.159.112.157 (51.159.112.157) port 80> GET /get HTTP/1.1> Host: 51.159.112.157> User-Agent: curl/8.7.1> Accept: */*>* Request completely sent off< HTTP/1.1 200 OK< server: istio-envoy< date: Mon, 24 Feb 2025 09:14:32 GMT< content-type: application/json< content-length: 522< access-control-allow-origin: *< access-control-allow-credentials: true< x-envoy-upstream-service-time: 2<{"args": {},"headers": {"Accept": "*/*","Host": "51.159.112.157","User-Agent": "curl/8.7.1","X-Envoy-Attempt-Count": "1","X-Envoy-External-Address": "62.210.16.37","X-Forwarded-Client-Cert": "By=spiffe://cluster.local/ns/test-app/sa/default;Hash=7e20594ba5421aa9df88b0d025498a5c51d02b0224daa3faea319c13a106d8b6;Subject=\"\";URI=spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway"},"origin": "62.210.16.37,100.64.2.46","url": "http://51.159.112.157/get"}* Connection #0 to host 51.159.112.157 left intact
It may be necessary to restart the Istio IngressGateway PodsLink to this anchor
Once you have added the configurations, you may need to restart the IngressGateway pods so that the changes to take effect.
Run the following command to delete the existing pods using kubectl
. Kubernetes will spin up new ones automatically after you launch the command:
kubectl delete pod -n istio-system -l istio=ingressgateway