Pods IP address from inside a container in the pod

0 votes

I'm trying to run Aerospike cluster in kubernetes and the config files need its own IP address. How do I get pods IP address from inside a container in the pod.

Aug 29, 2018 in Kubernetes by lina
• 8,220 points
3,560 views

1 answer to this question.

0 votes

Make sure that your pod yaml file has an environment variable that sets the ip address. You can do this by adding the config blog defined bellow:

 env:
    - name: MY_POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name
    - name: MY_POD_NAMESPACE
      valueFrom:
        fieldRef:
          fieldPath: metadata.namespace
    - name: MY_POD_IP
      valueFrom:
        fieldRef:
          fieldPath: status.podIP

Recreate the pod/rc and then try

echo $MY_POD_IP
answered Aug 29, 2018 by Kalgi
• 52,340 points