How to get client IP address from inside a Azure Kubernetes with a LoadBalancer service

丶灬走出姿态 提交于 2019-12-11 02:49:01

问题


I'm getting the node IP address instead of the client IP. Is it possible to get the client IP with a service of type LoadBalancer? Or will I need to use a ingress controller?

apiVersion: v1
kind: Service
metadata:
  name: app-svc
  labels:
    name: app-svc
    environment: dev
spec:
  type: LoadBalancer
  loadBalancerIP: XXX.XXX.XXX.XXX
  ports:
    - name: http-port
      port: 80
      targetPort: 80
      protocol: TCP
  selector:
      name: app-deploy

回答1:


You do not need any Ingress controller. However it is required to set the value of the spec.externalTrafficPolicy Service field to "Local" (the default is "Cluster") in Microsoft Azure.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: LoadBalancer
  externalTrafficPolicy: Local
  ...

See Using source IP.



来源:https://stackoverflow.com/questions/52248542/how-to-get-client-ip-address-from-inside-a-azure-kubernetes-with-a-loadbalancer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!