Day 35 - Mastering ConfigMaps and Secrets in Kubernetes???????
Amit Sharma
DevOps Engineer | Proficient in Docker, Kubernetes, Jenkins, Terraform, Git-GitHub | Deep Learning Enthusiast | AWS Cloud Enthusiast | Coding in Python & C++ |
In the vast universe of Kubernetes, where managing complex applications and their configurations is crucial, ConfigMaps and Secrets emerge as essential tools. These Kubernetes resources allow for the separation of configuration data and sensitive information from application code, promoting better security practices and maintainability.
ConfigMaps: Your Spaceship's Information Repository
ConfigMaps serve as a centralized repository for configuration data in Kubernetes. They store information in a key-value pair format, providing a straightforward method for managing non-sensitive data that applications need. Imagine ConfigMaps as labeled folders in a file cabinet, each containing specific information for different parts of your spaceship (Kubernetes cluster).
Creating a ConfigMap
Let's embark on Task 1 to create a ConfigMap for a Deployment:
# Create a ConfigMap from a file
kubectl create configmap my-configmap --from-file=config-file.properties -n <namespace-name>
# Update deployment.yml to include the ConfigMap
# deployment.yml excerpt:
# ...
# spec:
# template:
# metadata:
# labels:
# app: my-app
# spec:
# containers:
# - name: my-container
# image: my-image
# volumeMounts:
# - name: config-volume
# mountPath: /etc/config
# volumes:
# - name: config-volume
# configMap:
# name: my-configmap
# ...
# Apply the updated deployment
kubectl apply -f deployment.yml -n <namespace-name>
# Verify ConfigMap creation
kubectl get configmaps -n <namespace-name>
This example assumes you have a config-file.properties file with your configuration data.
Secrets: Safeguarding Sensitive Information
Secrets, as the name suggests, are designed to securely store sensitive data such as passwords, API keys, and other confidential information. They encrypt this data to prevent unauthorized access. In our spaceship analogy, Secrets act as a secure safe, ensuring that only authorized entities can access critical information.
领英推荐
Creating a Secret
Now, let's proceed with Task 2 to create a Secret for our Deployment:
# Create a Secret from literal values
kubectl create secret generic my-secret --from-literal=username=admin --from-literal=password=secretpassword -n <namespace-name>
# Update deployment.yml to include the Secret
# deployment.yml excerpt:
# ...
# spec:
# template:
# metadata:
# labels:
# app: my-app
# spec:
# containers:
# - name: my-container
# image: my-image
# volumeMounts:
# - name: secret-volume
# mountPath: /etc/secret
# volumes:
# - name: secret-volume
# secret:
# secretName: my-secret
# ...
# Apply the updated deployment
kubectl apply -f deployment.yml -n <namespace-name>
# Verify Secret creation
kubectl get secrets -n <namespace-name>
In this example, we create a Secret named my-secret with username and password literals.
By completing these tasks, you've not only gained insights into ConfigMaps and Secrets but also learned how to implement them in a practical Kubernetes deployment scenario. These resources play a pivotal role in achieving a robust and secure containerized environment. Safe travels in your Kubernetes journey! ??
I'm confident that this article will prove to be valuable, helping you discover new insights and learn something enriching .
thank you : )