Kubernates configMaps and Volumes
Store data is an everyday necessity in many applications; in this post, we want to cover some relevant aspects of persisting data using volumes and their application to save environment variables in Spring Boot.
Prerequisites
- Spring Boot: this is the framework used to develop the app.
- Clean Architecture: The project follows Martin Fowler's advice in the book "Clean Architecture.".
- Docker: This technology packages the essential components to deploy apps (you need to install it).
- Minikube: This tool enables a local environment to work with Kubernetes (you need to install it).
- Kubectl: is a client that works with the Kubernetes cluster (you need to install it).
The Project
Volumes are the type of objects that persist data in Kubernetes. However, it manages different kinds of them; in this case, we use the “emptyDir” class to store the environment variables because it allows storing data in the pod level so every container is allowed to get information about it.
A ConfigMap is an object to store parameters in Kubernates. It keeps the data in a key-value structure; Pods get information from them as environment variables, command-line, arguments, or configuration files.
The main idea is to deploy a Spring Boot App that stores the "application.yaml" file in the configMap object and persists the information in a Volume object of type "emptyDir".
The deploy-object is called in two points: “msvc-auth-pdn” using the envFrom label, and when it declares volumes, it calls the with the label “configMap.” the manifest file is it:
The App
Testing the app, you can download the repo-auth, open the deployment folder excute the command kubectl apply -f deployment-auth.yaml and use the command minikube service msvc-auth --url, It shows the url of the service.Use this URL to call the service deployed in Kubernetes; after that, you can use the Postman-collection and put the URL to make the POST request. The APP will be able to show the environment variable config.text present in the current configMap value.



Comments
Post a Comment