Использовать PROXY-протокол
- Скачайте манифест ingresscontroller.yaml.
- Внесите изменения в манифесте (поля отмечены тегом
[EDIT]
):
- включите PROXY-протокол:
entries: proxy-protocol: "true"
- создайте Service с параметрами:
type: LoadBalancer externalTrafficPolicy: Cluster annotations: loadbalancer.openstack.org/proxy-protocol: "true"
- Установите менеджер пакетов Helm.
- Создайте Ingress Controller с помощью манифеста из шага 1:
helm install ingress nginx-stable/nginx-ingress --values ingress.yaml
- Проверьте, что Ingress Controller установлен:
kubectl get svc
В выводе команды должен быть внешний IP-адрес с суффиксом nip.io:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-ingress LoadBalancer 10.100.100.100 123.123.123.123.nip.io 80:31039/TCP,443:31667/TCP 103s
Суффикс можно заменить на любой другой через аннотацию балансировщика loadbalancer.openstack.org/ingress-hostname-suffix: "test-suffix"
5. Создайте тестовый Deployment echo-сервера:
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: echoserver
namespace: default
labels:
app: echoserver
spec:
replicas: 1
selector:
matchLabels:
app: echoserver
template:
metadata:
labels:
app: echoserver
spec:
containers:
- name: echoserver
image: gcr.io/google-containers/echoserver:1.10
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
EOF
- Создайте Service для echo-сервера:
kubectl expose deployment echoserver --type=ClusterIP --target-port=8080
- Создайте правило Ingress для Service echo-сервера:
cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-proxy-protocol
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: test.com
http:
paths:
- path: /ping
pathType: Exact
backend:
service:
name: echoserver
port:
number: 8080
EOF
- Проверьте Ingress:
kubectl get ing
Вывод команды (IP-адрес может появиться спустя время):
NAME HOSTS ADDRESS PORTS AGE
test-proxy-protocol test.com 123.123.123.123.nip.io 80 2s
- Проверьте соединение:
ip=123.123.123.123.nip.io
curl -sH "Host: test.com" http://$ip/ping | sed '/^\s*$/d'
Вывод команды:
Hostname: echoserver-5c79dc5747-txwnz
Pod Information:
-no pod information available-
Server values:
server_version=nginx: 1.13.3 - lua: 10008
Request Information:
client_address=10.10.10.31
method=GET
real path=/ping
query=
request_version=1.1
request_scheme=http
request_uri=http://test.com:8080/ping
Request Headers:
accept=*/*
connection=close
host=test.com
user-agent=curl/7.74.0
x-forwarded-for=<xxx>
x-forwarded-host=test.com
x-forwarded-port=80
x-forwarded-proto=http
x-real-ip=<xxx>
Request Body:
-no body in request-