How to know a Pod's own IP address from inside a container in the Pod?

前端 未结 9 1548
庸人自扰
庸人自扰 2020-11-30 17:50

Kubernetes assigns an IP address for each container, but how can I acquire the IP address from a container in the Pod? I couldn\'t find the way from documentations.

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 18:23

    Even simpler to remember than the sed approach is to use awk.

    Here is an example, which you can run on your local machine:

    kubectl describe pod `` | grep IP | awk '{print $2}'
    

    The IP itself is on column 2 of the output, hence $2 .

提交回复
热议问题