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.
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 .
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.
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).
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.)
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
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