Reputation: 33
I am currently learning Kubernetes, and i am facing a bit of a wall.
I try to pass environmentalvariables from my YAML file definition
to my container. But the variables seem not to be present afterwards.
kubectl exec <pod name> -- printenv
gives me the list of environmental
variables. But the ones i defined in my YAML file is not present.
I defined the environment variables in my deployment as shown below:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-boot
labels:
app: hello-world-boot
spec:
selector:
matchLabels:
app: hello-world-boot
template:
metadata:
labels:
app: hello-world-boot
containers:
- name: hello-world-boot
image: lightmaze/hello-world-spring:latest
env:
- name: HELLO
value: "Hello there"
- name: WORLD
value: "to the entire world"
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 8080
selector:
app: hello-world-boot
Hopefully someone can see where i failed in the YAML :)
Upvotes: 3
Views: 8325
Reputation: 311238
If I correct the errors in your Deployment
configuration so that it looks like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-boot
labels:
app: hello-world-boot
spec:
selector:
matchLabels:
app: hello-world-boot
template:
metadata:
labels:
app: hello-world-boot
spec:
containers:
- name: hello-world-boot
image: lightmaze/hello-world-spring:latest
env:
- name: HELLO
value: "Hello there"
- name: WORLD
value: "to the entire world"
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 8080
And deploy it into my local minikube
instance:
$ kubectl apply -f pod.yml
Then it seems to work as you intended:
$ kubectl exec -it hello-world-boot-7568c4d7b5-ltbbr -- printenv
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
HOSTNAME=hello-world-boot-7568c4d7b5-ltbbr
TERM=xterm
HELLO=Hello there
WORLD=to the entire world
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT=tcp://10.96.0.1:443
LANG=C.UTF-8
JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
JAVA_VERSION=8u212
JAVA_ALPINE_VERSION=8.212.04-r0
HOME=/home/spring
If you look at the above output, you can see both the HELLO
and WORLD
environment variables you defined in your Deployment
.
Upvotes: 5