如何在 Kubernetes 中提供 .env 文件。我正在使用 Node.JS 包,它通过 .env 文件填充我的 process.env。
您可以通过两种方式完成此操作:
env在配置文件中包含该字段。前任:
apiVersion: v1
kind: Pod
metadata:
name: envar-demo
labels:
purpose: demonstrate-envars
spec:
containers:
- name: envar-demo-container
image: gcr.io/google-samples/node-hello:1.0
env:
- name: DEMO_GREETING
value: "Hello from the environment"
- name: DEMO_FAREWELL
value: "Such a sweet sorrow"
Run Code Online (Sandbox Code Playgroud)
data字段引用键值对中的值。apiVersion: v1
kind: ConfigMap
metadata:
name: special-config
namespace: default
data:
SPECIAL_LEVEL: very
SPECIAL_TYPE: charm
Run Code Online (Sandbox Code Playgroud)
现在,用于envFrom将 ConfigMap 的所有数据定义为容器环境变量,例如:
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "env" ]
envFrom:
- configMapRef:
name: special-config
restartPolicy: Never
Run Code Online (Sandbox Code Playgroud)
env您甚至可以通过如下所示指定单个字段:
env:
- name: SPECIAL_LEVEL_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: SPECIAL_LEVEL
- name: SPECIAL_TYPE_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: SPECIAL_TYPE
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5345 次 |
| 最近记录: |