我使用以下代码创建了一个 Nginx 入口和服务:
apiVersion: v1
kind: Service
metadata:
name: myservice
spec:
type: ClusterIP
selector:
name: my-app
ports:
- port: 8000
targetPort: 8000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myingress
annotations:
kubernetes.io/ingress.class: nginx
labels:
name: myingress
spec:
rules:
- host: mydomain.com
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: my-service
port:
number: 8000
安装了 Nginx 入口:
helm install ingress-nginx ingress-nginx/ingress-nginx
.
我还为 ELB 启用了代理协议。但是在 nginx 日志中,我看不到 X-Forwarded-For 和 X-Real-IP 标头的真实客户端 IP。这是我在应用程序日志中看到的最终标题:
X-Forwarded-For:[192.168.21.145] X-Forwarded-Port:[80] X-Forwarded-Proto:[http] X-Forwarded-Scheme:[http] X-Real-Ip:[192.168.21.145] X-Request-Id:[1bc14871ebc2bfbd9b2b6f31] X-Scheme:[http]
如何获取真正的客户端 IP 而不是入口 pod IP?还有一种方法可以知道 ELB 将哪些标头发送到入口?