Can Kubernetes deployment manifest file have both -env and -envFrom keys?
I have set a secrets.yaml
file to set the environment variables and also have environment variables that are hard coded.
Can I have both of them set using both -env
and -envFrom
in the YAML files?
CodePudding user response:
The answer is yes, and you can simply try it out.....
apiVersion: v1
kind: Namespace
metadata:
name: codewizard
---
apiVersion: v1
kind: ConfigMap
metadata:
name: codewizard-configmap
namespace: codewizard
data:
APP_ENV: production
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: codewizard-busybox
namespace: codewizard
spec:
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: busybox
image: busybox
command: [ "/bin/bash", "-c", "--" ]
args: [ "while true; do printenv; done;" ]
resources:
limits:
memory: "128Mi"
cpu: "500m"
envFrom:
- configMapRef:
name: codewizard-configmap
env:
- name: OS
value: Linux
- Now check the pod's log and you will see all the env values
kubectl exec \
-n codewizard \
$(kubectl get pods -n codewizard -o jsonpath='{.items[0].metadata.name}') \
-- sh -c "printenv"
CodePudding user response:
Can kubernetes deployment manifest file have both -env and -envFrom keys?
Yes.
...
envFrom:
- secretRef:
name: <name of your secret>
env:
- name: <variable name>
value: <hardcoded value>
- name: <variable name>
valueFrom:
secretKeyRef:
name: <name of your secret>
key: <If I only want this and not all the keys in the secret>