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
visitsfile. - Introduce a new endpoint
/visitsto display the recorded visits.
- Test the changes:
- Update your
docker-compose.ymlto include a new volume with yourvisitsfile. - Verify that the enhancements work as expected, you must see the updated number in the
visitsfile on the host machine. - Update the
README.mdfor 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
lab12branch to the main branch in your own repository.
4 Points:
-
Understand ConfigMaps:
- Read about ConfigMaps in Kubernetes:
-
Mount a Config File:
- Create a
filesfolder with aconfig.jsonfile. - Populate
config.jsonwith data in JSON format. - Use Helm to mount
config.json:- Create a
configMapmanifest, extracting data fromconfig.jsonusing.Files.Get. - Update
deployment.yamlwithVolumesandVolumeMounts. - 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.mdin thek8sfolder and include the output of relevant commands.
- Create
List of Requirements:
config.jsonin thefilesfolder.configMapretrieving data fromconfig.jsonusing.Files.Get.Volumes andVolumeMounts indeployments.yml.12.mddocumenting 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
envFromproperty. - Provide proof with the output of the
envcommand 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
lab12branch 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.