Use the PROXY protocol in a Managed Kubernetes cluster
PROXY protocol works correctly only with Managed Kubernetes clusters version 1.21.10 or higher. You can upgrade the cluster version.
These are instructions for configuring access through the Nginx Ingress Controller.
-
Download the ingresscontroller.yaml manifest.
-
Make changes to the manifest fields that are marked with the
[EDIT]tag:- enable the PROXY protocol:
config:use-proxy-protocol: true- create a Service with parameters:
type: LoadBalancerexternalTrafficPolicy: Clusterannotations:loadbalancer.openstack.org/proxy-protocol: "true"Do not change the value of
the externalTrafficPolicyparameter. -
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 the 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 output of the command should contain an external IP address with the suffix nip.io:
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 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 Service echo server:
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 out Ingress:
kubectl get ingCommand output (IP address may appear after a while):
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-