In this lab, you'll delve into Kubernetes ConfigMaps, focusing on managing non-confidential data and upgrading your application for persistence. ConfigMaps provide a way to decouple configuration artifacts from image content, allowing you to manage configuration data separately from the application.
6 Points:
In this task, you'll enhance your application to persist data and explore ConfigMaps in Kubernetes.
-
Upgrade Your Application:
- Modify your application to:
- Implement a counter logic in your application to keep track of the number of times it's accessed.
- Save the counter number in the
visits
file. - Introduce a new endpoint
/visits
to display the recorded visits.
- Test the changes:
- Update your
docker-compose.yml
to include a new volume with yourvisits
file. - Verify that the enhancements work as expected, you must see the updated number in the
visits
file on the host machine. - Update the
README.md
for your application.
- Update your
- Modify your application to:
-
Create Pull Requests:
- Submit a PR to merge your changes into the main branch of the forked repository.
- Create a PR from the
lab12
branch to the main branch in your own repository.
4 Points:
-
Understand ConfigMaps:
- Read about ConfigMaps in Kubernetes:
-
Mount a Config File:
- Create a
files
folder with aconfig.json
file. - Populate
config.json
with data in JSON format. - Use Helm to mount
config.json
:- Create a
configMap
manifest, extracting data fromconfig.json
using.Files.Get
. - Update
deployment.yaml
withVolumes
andVolumeMounts
. - Install the updated Helm chart and verify success:
- Retrieve the list of pods:
kubectl get po
. - Use the pod name as proof of successful deployment.
- Check the ConfigMap inside the pod, e.g.,
kubectl exec demo-758cc4d7c4-cxnrn -- cat /config.json
.
- Retrieve the list of pods:
- Create a
- Create a
-
Documentation:
- Create
12.md
in thek8s
folder and include the output of relevant commands.
- Create
List of Requirements:
config.json
in thefiles
folder.configMap
retrieving data fromconfig.json
using.Files.Get
.Volume
s andVolumeMount
s indeployments.yml
.12.md
documenting the results of commands.
2.5 Points:
-
Upgrade Bonus App:
- Implement persistence logic in your bonus app.
-
ConfigMap via Environment Variables:
- Utilize ConfigMap via environment variables in a running container using the
envFrom
property. - Provide proof with the output of the
env
command inside your container.
- Utilize ConfigMap via environment variables in a running container using the
Guidelines:
- Maintain clear and organized documentation.
- Use appropriate naming conventions for files and folders.
- For your repository PR, ensure it's from the
lab12
branch to the main branch.
Note: Clear documentation is crucial to demonstrate successful data persistence and ConfigMap utilization in Kubernetes. Explore the bonus tasks to further enhance your skills.