Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get a Kubernetes pod's name from its IP address?

Tags:

kubernetes

How do I get a pod's name from its IP address? What's the magic incantation of kubectl + sed/awk/grep/etc regardless of where kubectl is invoked?

like image 226
Matthew Adams Avatar asked Jan 10 '17 07:01

Matthew Adams


People also ask

How do I find my Kubernetes deployment name?

Run kubectl get deployments to check if the Deployment was created. When you inspect the Deployments in your cluster, the following fields are displayed: NAME lists the names of the Deployments in the namespace. READY displays how many replicas of the application are available to your users.

How do I get the pods hostname in Kubernetes?

Currently when a pod is created, its hostname is the Pod's metadata.name value. With v1. 2, users can specify a Pod annotation, pod.beta.kubernetes.io/hostname , to specify what the Pod's hostname should be. The Pod annotation, if specified, takes precedence over the Pod's name, to be the hostname of the pod.

How do I find my Kubernetes node name?

Typically, the node name is given with "--hostname-override" option when starting the kubelet. So, the following command would give the node name if --hostname-override is set.


1 Answers

Example:

kubectl get pods -o wide NAME                               READY     STATUS    RESTARTS   AGE       IP            NODE alpine-3835730047-ggn2v            1/1       Running   0          5d        10.22.19.69   ip-10-35-80-221.ec2.internal  

get pod name by IP

kubectl get --all-namespaces  --output json  pods | jq '.items[] | select(.status.podIP=="10.22.19.69")' | jq .metadata.name "alpine-3835730047-ggn2v" 

get container name by IP

kubectl get --all-namespaces  --output json  pods | jq '.items[] | select(.status.podIP=="10.22.19.69")' | jq .spec.containers[].name "alpine" 
like image 200
Camil Avatar answered Sep 16 '22 12:09

Camil