我有一个情况,我想将 pod 的 IP 地址设置为容器环境变量以及端口的一部分(例如,可以将其硬编码为 default8080)
类似于下面的内容,但我也需要附加端口作为其中的一部分。这样 APPLICATION_SERVER 的结果将是111。。.000:8080我猜是这样的。
- name: APPLICATION_SERVER
valueFrom:
fieldRef:
fieldPath: status.podIP
Run Code Online (Sandbox Code Playgroud)
您正在查找的值可以作为环境变量从 Downward API 中获取
\n\napiVersion: v1\nkind: Pod\nmetadata:\n name: dapi-envars\nspec:\n containers:\n - name: test-container\n image: k8s.gcr.io/busybox\n command: [ "sh", "-c"]\n args:\n - while true; do\n echo -en \'\\n\';\n echo "Application Server $(APPLICATION_SERVER)";\n sleep 10;\n done;\n env:\n - name: MY_POD_IP\n valueFrom:\n fieldRef:\n fieldPath: status.podIP\n - name: APPLICATION_SERVER\n value: "$(MY_POD_IP):8080"\nRun Code Online (Sandbox Code Playgroud)\n\n输出
\n\nkubectl logs dapi-envars\n\nApplication Server 10.244.0.7:8080\n\nApplication Server 10.244.0.7:8080\n\nApplication Server 10.244.0.7:8080\n\nApplication Server 10.244.0.7:8080\n\nApplication Server 10.244.0.7:8080\nRun Code Online (Sandbox Code Playgroud)\n\nhttps://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
\n| 归档时间: |
|
| 查看次数: |
2955 次 |
| 最近记录: |