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
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.
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With