

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Config Maps
incomplete
2: Applying the Config Map
incomplete
3: Config Maps Are Insecure
incomplete
4: Crawler
incomplete
This lesson's interactive features are locked, please to keep using them
There are several ways to manage environment variables in Kubernetes. One of the most common ways is to use ConfigMaps. ConfigMaps allow us to decouple our configurations from our container images, which is important because we don't want to have to rebuild our images every time we want to change a configuration value.
In a Dockerfile we can set environment variables like this:
ENV PORT=3000
The trouble is, that means that everyone using that image will have to use port 3000. It also means that if we want to change the port, we have to rebuild the image.
First, let's take a closer look at our crashing pod and try to figure out why it's crashing.
kubectl get pods
Copy the pod name and then get the logs:
kubectl logs <pod-name>
You should see that a specific environment variable is missing! Let's fix that.
Create a new file. Let's call it api-configmap.yaml. Add the following YAML to it:
apiVersion: v1kind: ConfigMapmetadata/name: synergychat-api-configmapdata/API_PORT: "8080"Next, apply the config map:
kubectl apply -f api-configmap.yaml
Now, we haven't yet connected the config map to our pod, so it should still be crashing. However, for now, let's just validate that the config map was created successfully:
kubectl get configmaps
Run:
kubectl proxy
Run and submit the CLI tests.