Mastering ConfigMaps and Secrets in Kubernetes

2 min read

What are ConfigMaps and Secrets in k8s

In Kubernetes, ConfigMaps and Secrets are used to store configuration data and secrets, respectively. ConfigMaps store configuration data as key-value pairs, while Secrets store sensitive data in an encrypted form.

ConfigMap

ConfigMap: A ConfigMap is an API object in Kubernetes used to store non-sensitive configuration data as key-value pairs. It provides a way to decouple configuration details from the application code, allowing you to modify the configuration without rebuilding or redeploying the application. Typical use cases for ConfigMap include storing environment variables, command-line arguments, configuration files, or any other configuration data required by your application.

Secrets

Secrets in Kubernetes are similar to ConfigMaps but are specifically designed for managing sensitive data, such as passwords, API tokens, or TLS certificates. Secrets provide a secure way to store and distribute this sensitive information to containers running within pods.

How to Create ConfigMap?

(let's make it simple)

  1. clone the repo

    git clone https://github.com/LondheShubham153/django-todo-cicd

  2. cd to MYSQL-DB

  3. open the file content confingMap

  4. use the command kubectl apply -f configMap.yaml

How to create Secrets?

  1. create a secret yaml file

     apiVersion: v1
     kind: Secret
     metadata:
       name: mysql-secret
     type: Opaque
     data:
       password: dHJhaW53aXRoc2h1YmhhbQ==
    
  2. just run kubectl apply -f secrects.yaml

    And Here it's Done!!

ConfigMap and secrets are important for the deployment to run as all the info which are required and confidential passwords are present inside the container which helps containers to run in any environment.

Happy Learning!!