Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the External IP of a Kubernetes service as a raw value?

I am running an application with GKE. It works fine but I can not figure out how to get the external IP of the service in a machine readable format. So i am searching a gcloud or kubectl command that gives me only the external IP or a url of the format http://192.168.0.2:80 so that I can cut out the IP.

like image 270
stm Avatar asked Dec 25 '17 14:12

stm


People also ask

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 find my Kubernetes public IP?

Go to the kubectl command-line tool Use the command-line tool, also known as kubectl, to find the IP address of a Kubernetes pod. This tool fetches pod information from the Kubernetes API to let you run Kubernetes commands to deploy applications, inspect and manage cluster resources, and view logs.

How do I find the IP address of Kubernetes nodes?

if you are looking for the address of your kubernetes API endpoint server (the endpoint to which kubectl talks) then in case of clusters created manually with kubeadm , this will be the IP of the master node that you created with kubeadm init command (assuming single master case).


2 Answers

You can use the jsonpath output type to get the data directly without needing the additional jq to process the json:

kubectl get services --namespace ingress-nginx nginx-ingress-controller --output jsonpath='{.status.loadBalancer.ingress[0].ip}'

(Be sure to replace the namespace and service name, respectively, with yours.)

like image 99
kenny Avatar answered Sep 19 '22 09:09

kenny


Maybe not GKE as my clusters are on AWS, but I assume logic will be similar. When you kubectl get svc you can select output format and it will show more then just the "normal" get. For me, with ELB based services to het LB hostname it's enough to run ie. kubectl -n kube-system get svc cluster-nginx-ingress-controller -o json | jq .status.loadBalancer.ingress.hostname

like image 39
Radek 'Goblin' Pieczonka Avatar answered Sep 17 '22 09:09

Radek 'Goblin' Pieczonka