Using PROXY protocol in Managed Kubernetes cluster
The PROXY protocol works correctly only with Managed Kubernetes clusters of version 1.21.10 or higher. You can upgrade the cluster version.
This is a guide for configuring access via the Nginx Ingress Controller.
-
Download the ingresscontroller.yaml manifest.
-
Make changes to the manifest fields that are marked with the
[EDIT]:tag:- enable PROXY protocol:
config:use-proxy-protocol: true- create a Service with the following parameters:
type: LoadBalancerexternalTrafficPolicy: Clusterannotations:loadbalancer.openstack.org/proxy-protocol: "true"Do not change the value of the
externalTrafficPolicyparameter. -
Install the Helm package manager.
-
Optional: add the ingress-nginx repository to Helm and update it:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginxhelm repo update -
Create an Ingress Controller using the manifest from step 1:
helm install ingress-nginx/ingress-nginx --values ingresscontroller.yaml --generate-name -
Check that the Ingress Controller is installed:
kubectl get svcThe command output should contain an external IP address with the nip.io suffix:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEingress-nginx-ingress LoadBalancer 10.100.100.100 123.123.123.123.nip.io 80:31039/TCP,443:31667/TCP 103s -
Create a test deployment of the echo server:
cat <<EOF | kubectl apply -f -apiVersion: apps/v1kind: Deploymentmetadata:name: echoservernamespace: defaultlabels:app: echoserverspec:replicas: 1selector:matchLabels:app: echoservertemplate:metadata:labels:app: echoserverspec:containers:- name: echoserverimage: gcr.io/google-containers/echoserver:1.10imagePullPolicy: IfNotPresentports:- containerPort: 8080EOF -
Create a Service for the echo server:
kubectl expose deployment echoserver --type=ClusterIP --target-port=8080 -
Create an Ingress rule for the echo server Service:
cat <<EOF | kubectl apply -f -apiVersion: networking.k8s.io/v1kind: Ingressmetadata:name: test-proxy-protocolnamespace: defaultspec:ingressClassName: "nginx"rules:- host: test.comhttp:paths:- path: /pingpathType: Exactbackend:service:name: echoserverport:number: 8080EOF -
Check the Ingress:
kubectl get ingCommand output (the IP address may take some time to appear):
NAME HOSTS ADDRESS PORTS AGEtest-proxy-protocol test.com 123.123.123.123.nip.io 80 2s -
Check the connection:
ip=123.123.123.123.nip.iocurl -sH 'Host: test.com' http://$ip/ping | sed '/^\s*$/d'Command output:
Hostname: echoserver-5c79dc5747-txwnzPod Information:-no pod information available-Server values:server_version=nginx: 1.13.3 - lua: 10008Request Information:client_address=10.10.10.31method=GETreal path=/pingquery=request_version=1.1request_scheme=httprequest_uri=http://test.com:8080/pingRequest Headers:accept=*/*connection=closehost=test.comuser-agent=curl/7.74.0x-forwarded-for=<xxx>x-forwarded-host=test.comx-forwarded-port=80x-forwarded-proto=httpx-real-ip=<xxx>Request Body:-no body in request-