Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 905
lmcarreiro Avatar asked Sep 09 '18 20:09

lmcarreiro


People also ask

How do I get the IP address for Kubernetes service?

To find the cluster IP address of a Kubernetes pod, use the kubectl get pod command on your local machine, with the option -o wide . This option will list more information, including the node the pod resides on, and the pod's cluster IP. The IP column will contain the internal cluster IP address for each pod.

What is Load Balancer IP in Kubernetes?

This provides an externally-accessible IP address that sends traffic to the correct port on your cluster nodes, provided your cluster runs in a supported environment and is configured with the correct cloud load balancer provider package. You can also use an Ingress in place of Service.

How can I get Kubernetes cluster IP from outside?

To reach the ClusterIp from an external computer, you can open a Kubernetes proxy between the external computer and the cluster. You can use kubectl to create such a proxy. When the proxy is up, you're directly connected to the cluster, and you can use the internal IP (ClusterIp) for that Service .

How do I set a static IP address for Kubernetes load balancer?

To create a LoadBalancer service with the static public IP address, add the loadBalancerIP property and the value of the static public IP address to the YAML manifest. Create a file named load-balancer-service. yaml and copy in the following YAML. Provide your own public IP address created in the previous step.


1 Answers

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.

like image 79
Antoine Cotten Avatar answered Sep 30 '22 19:09

Antoine Cotten