我已經在我的虛擬機上安裝了 kubernetes。我在 Kubernetes 上的 pod 內運行我的應用程式。
現在我想在 pod 內運行的應用程式中獲取我的 VM 的 IP 地址。有沒有辦法做到這一點?
uj5u.com熱心網友回復:
以下是獲取主機 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將列印您的IP。
uj5u.com熱心網友回復:
是的,可以從特定節點上運行的 pod 獲取主機 ip 和主機名。使用以下變數獲取這些值
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
以下鏈接會有所幫助-> https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/445048.html
