I have installed kubernetes on my VM. And I run my application inside pod on kubernetes.
Now I want to get IP address of my VM in my application which is running inside pod. Is there any way to do this?
CodePudding user response:
Here's how you can get the host IP:
apiVersion: v1
kind: Pod
metadata:
name: busybox
spec:
restartPolicy: Never
containers:
- name: busybox
image: busybox
command: ["ash","-c","echo $MY_HOST_IP && sleep 3600"]
env:
- name: MY_HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
kubectl logs busybox
will print you the IP.
CodePudding user response:
Yes, it is possible to get the host ip and the hostname from the pod running on a specific node. Use the below variable to get those values
spec.nodeName - the name of the node to which the scheduler always attempts to schedule the pod
status.hostIP - the IP of the node to which the Pod is assigned
following link would be helpful --> https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/