记录真实IP地址

有时候我们需要在容器中获取客户端真实的IP等信息,而经过NginxIngressController转发后,这些信息不一定拿得到,所以我们需要对NginxIngressController进行配置。

$ kubectl -n ingress-nginx edit configmap ingress-nginx-controller 
...
data:
  proxy-set-headers: "ingress-nginx/custom-headers"
cat >> nginx-custom-headers-cm.yaml <<-EOF
apiVersion: v1
kind: ConfigMap
metadata:
  name: custom-headers
  namespace: ingress-nginx
data:
  client-ip: $remote_addr
EOF