How to get the service IP in Kubernetes?

8/25/2015

I ran a local cluster according to its official doc here. I followed the steps and it worked properly until I set a replica and tried to exposed it. I mean:

./kubectl expose rc nginx --port=80

the output is this:

NAME      LABELS      SELECTOR    IP(S)     PORT(S)
nginx     run=nginx   run=nginx             80/TCP

When I tried another time it sayed the the same service is running. How can I figure out the IP?

-- Hadi
cluster-computing
docker
kubernetes
ubuntu

4 Answers

9/19/2019
kubectl get service/servicename -o jsonpath='{.spec.clusterIP}'
-- Leopd
Source: StackOverflow

1/24/2018
kubectl get svc <your-service> -o yaml | grep ip
-- Rubber Duck
Source: StackOverflow

8/25/2015

The IP should be the external IP of your master-node. If you're running locally it should be localhost or your VM.

Of course with the given port added.

127.0.0.1:80

for example.

PS: Be sure you have containers/pods running already by running:

kubectl get pods

If this doesn't work, I would suggest proxying it, for test-purposes at least.

Kubectl proxy

-- NegatioN
Source: StackOverflow

9/19/2019

There are a couple of ways to do this:

kubectl get svc <service-name> -o yaml | grep clusterIP

or for example:

kubectl describe svc <service-name> | grep IP

-- Filipe Freire
Source: StackOverflow