[英]Getting env variables to an NGNIX react kubernetes pod
I have an ngnix kubernetes pod that I need to pass an .env
file to but I can't get it to work.我有一个 ngnix kubernetes pod,我需要将
.env
文件传递给它,但我无法让它工作。
Docker file for the pod: Pod 的 Docker 文件:
FROM node:12-alpine as build-step
RUN mkdir /app
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
RUN npm run build
FROM nginx:1.17.1-alpine
COPY --from=build-step /app/build /usr/share/nginx/html
I've tried with to pass the env with the configmap:我试过用 configmap 传递 env:
apiVersion: v1
kind: ConfigMap
metadata:
name: test-front-app
data:
ENV_TEST: "TEST"
And with passing the env
in the Deployment
but neither worked.并在
Deployment
传递env
但都没有奏效。
edit the deployment file:编辑部署文件:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test-front-app
name: test-front-app
spec:
replicas: 2
selector:
matchLabels:
name: test-front-app
template:
metadata:
labels:
name: test-front-app
spec:
imagePullSecrets:
- name: gcr-json-key
containers:
- name: front-test
image: gcr.io/PROJECT_ID/IMAGE:TAG
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
env:
- name: TEST_ONE
value: "test-value-one/"
envFrom:
- configMapRef:
name: test-front-app
Your ConfigMap test-front-app
key can be accessed as env like below.您的 ConfigMap
test-front-app
密钥可以作为 env 访问,如下所示。
env:
- name: TEST_ONE
valueFrom:
configMapKeyRef:
name: test-front-app
key: ENV_TEST
In this way TEST_ONE
variable with value of TEST
will be passed to deployment.这样,值为
TEST
TEST_ONE
变量将被传递给部署。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.