Matthew Tromp
Matthew Tromp

Reputation: 343

Get pod with given IP in Kubernetes go api

I'm using the kubernetes go api. I have the IP of a pod, and I want to find the v1.pod object (or just name and namespace) of the pod that has that IP. How can I go about this?

Upvotes: 1

Views: 294

Answers (1)

Matthew Tromp
Matthew Tromp

Reputation: 343

Turns out you need to use a FieldSelector. The field in this case is status.podIP.

import (
    [...]
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    [...]
)

[...]

pods, err := clientset.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{FieldSelector: "status.podIP=" + address})

Where clientset is a *kubernetes.Clientset and address is the string IP of the pod

Upvotes: 2

Related Questions