Client-go: How to get pods ip?

Created on 28 Sep 2017  路  5Comments  路  Source: kubernetes/client-go

How to get pod ip?

Most helpful comment

pods, err := clientset.CoreV1().Pods("mpich-system").List(metav1.ListOptions{})
if err != nil {
    // handle error
}
for _, pod := range pods.Items {
    fmt.Println(pod.Name, pod.Status.PodIP)
}

All 5 comments

pods, err := clientset.CoreV1().Pods("mpich-system").List(metav1.ListOptions{})
if err != nil {
    // handle error
}
for _, pod := range pods.Items {
    fmt.Println(pod.Name, pod.Status.PodIP)
}

@ericchiang Thanks

Pods("") should get the namespace but where do you find it? I am a bit lost it's all the time nil/empty

Now it says I have no access ..

load: "panic: pods is forbidden: User "system:serviceaccount:default:default" cannot list resource "pods" in API group "" in the namespace "default"

I can't make it work.. I tried to manage multiple stuff in the IAM but still nothing..

Now it says I have no access ..

load: "panic: pods is forbidden: User "system:serviceaccount:default:default" cannot list resource "pods" in API group "" in the namespace "default"

I can't make it work.. I tried to manage multiple stuff in the IAM but still nothing..

@Emixam23 you need to give appropriate roles to your service account via clusterrolebinding or role binding. The default serviceaccount has not permission to list resources.

For example:

kubectl create role some-role --verb=get --verb=list --verb=watch --verb=update --resource=pods --resource=endpoints --resource=services

kubectl create rolebinding some-role-binding --role=some-role --serviceaccount=default:default

Or you can create a custom serviceaccount and give roles to it and use that serviceaccount.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaron276h picture aaron276h  路  4Comments

tamalsaha picture tamalsaha  路  6Comments

yashbhutwala picture yashbhutwala  路  4Comments

tamalsaha picture tamalsaha  路  3Comments

alexec picture alexec  路  5Comments