How to Find Service IP in Kubernetes Quickly
To find the IP address of a Kubernetes service, use the
kubectl get service [SERVICE_NAME] command. The service IP appears under the CLUSTER-IP column, showing the internal IP assigned to that service.Syntax
The basic command to find a service IP in Kubernetes is:
kubectl get service [SERVICE_NAME]: Shows details of the specified service including its IP.kubectl get services: Lists all services with their IPs.
The CLUSTER-IP field in the output is the internal IP address of the service inside the Kubernetes cluster.
bash
kubectl get service [SERVICE_NAME]
Example
This example shows how to find the IP of a service named my-service in the default namespace.
bash
kubectl get service my-service
Output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-service ClusterIP 10.96.123.45 <none> 80/TCP 5d
Common Pitfalls
Common mistakes when finding service IPs include:
- Using the wrong service name or namespace, which results in "NotFound" errors.
- Confusing
EXTERNAL-IPwithCLUSTER-IP. TheCLUSTER-IPis the internal IP inside the cluster, whileEXTERNAL-IPis for outside access if configured. - Trying to access the service IP from outside the cluster without proper network setup.
bash
kubectl get service wrong-service-name # Correct usage: kubectl get service my-service
Output
Error from server (NotFound): services "wrong-service-name" not found
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-service ClusterIP 10.96.123.45 <none> 80/TCP 5d
Quick Reference
| Command | Description |
|---|---|
| kubectl get service [SERVICE_NAME] | Show details including IP of a specific service |
| kubectl get services | List all services with their IPs |
| kubectl describe service [SERVICE_NAME] | Show detailed info including endpoints and IPs |
| kubectl get svc -n [NAMESPACE] | List services in a specific namespace |
Key Takeaways
Use
kubectl get service [SERVICE_NAME] to see the service IP under CLUSTER-IP.The
CLUSTER-IP is the internal IP inside the Kubernetes cluster.Check the correct namespace and service name to avoid errors.
EXTERNAL-IP is different and only shows if the service is exposed outside the cluster.Use
kubectl describe service for more detailed information about the service.