Stav Alfi
Stav Alfi

Reputation: 13923

How to get k8s master ip address?

I have learn that I need to create a service so the deployment pods's ports will be exposed in the cluster. so the service provides me the port, and all is left is to find the cluster ip.

Problem

using https://github.com/kubernetes-client/javascript, I have created a deployment and a service.

Question

I'm not sure how to get the master address.

In bash, I would do:

> kubectl cluster-info
Kubernetes master is running at https://<this-is-what-I-need>:8443
KubeDNS is running at https://<this-is-what-I-need>:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

but I'm not sure how to extract the ip. is there a better bash command? or any api for that? (maybe in https://github.com/kubernetes-client/javascript)?


more context

I created a demployment on my local machine for a docker image that exposes a service on port 4873.

> kubectl get service stav-service1
NAME            TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
stav-service1   NodePort   10.104.10.251   <none>        4873:30219/TCP   39m

> kubectl get deployment stav-deployment1
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
stav-deployment1   1/1     1            1           41m

I can reach that service from my local machine by running curl http://192.168.64.2:30219

Upvotes: 2

Views: 8209

Answers (2)

Suben Saha
Suben Saha

Reputation: 1848

If you are using minikube as you stated in your comment please try the following one:

minikube ip

Upvotes: 1

hdhruna
hdhruna

Reputation: 866

Is this what you are looking for?

kubectl get nodes --selector=node-role.kubernetes.io/master -o jsonpath='{$.items[*].status.addresses[?(@.type=="InternalIP")].address}'

Upvotes: 5

Related Questions