# Day 34: Mastering ConfigMaps and Secrets in Kubernetes🔒🔑

## 1\. 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.

* *Example :- Imagine you're in charge of a big spaceship (Kubernetes cluster) with lots of different parts (containers) that need information to function properly. ConfigMaps are like a file cabinet where you store all the information each part needs in simple, labeled folders (key-value pairs). Secrets, on the other hand, are like a safe where you keep the important, sensitive information that shouldn't be accessible to just anyone (encrypted data). So, using ConfigMaps and Secrets, you can ensure each part of your spaceship (Kubernetes cluster) has the information it needs to work properly and keep sensitive information secure! 🚀*
    

# *<mark>ConfigMaps;</mark>*

A ConfigMap is an API object used to store non-confidential data in key-value pairs. [Pods](https://kubernetes.io/docs/concepts/workloads/pods/) can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a [volume](https://kubernetes.io/docs/concepts/storage/volumes/).

A ConfigMap allows you to decouple environment-specific configuration from your [container images](https://kubernetes.io/docs/reference/glossary/?all=true#term-image), so that your applications are easily portable.

write a ymal ffile for smps.ten applyu it on culster demand.

## <mark>Task 1:</mark>

* Create a ConfigMap for your Deployment.
    
    we have create configmap suing below command::
    
    kubectl create configmap &lt;configmap name&gt; --from-file=&lt;read file&gt;
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703267992495/f1efea33-58e5-4474-9c12-be75bb283a98.png align="center")
    
* Create a ConfigMap for your Deployment using a file or the command line
    
    kubectl create configmap &lt;configmap name&gt; --from-file=&lt;read file&gt; -n nameaspace
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703268177616/22f72bb4-2fa1-4dcc-98b6-7f63d4ef0e5a.png align="center")
    
* Update the deployment.yml file to include the ConfigMap
    
    ```bash
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: todo-deployment
      labels:
        app: todo-app
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: todo-app
      template:
        metadata:
          labels:
            app: todo-app
        spec:
          containers:
            - name: todo-app
              image: 'prad87420/toda-node-app'
              ports:
                - containerPort: 8000
              envFrom:
                - configMapRef:
                    name: devops5
    ```
    
* Apply the updated deployment using the command: `kubectl apply -f deployment.yml -n <namespace-name>`
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703269588403/c512e94e-aa9e-455a-abe6-dc73a99856ee.png align="center")

* Verify that the ConfigMap has been created by checking the status of the ConfigMaps in your Namespace.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703269782620/a51a8668-a031-49c5-ad9b-a4f2252f82d2.png align="center")
    

# **<mark>Secrets;</mark>**

A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key. Such information might otherwise be put in a [Pod](https://kubernetes.io/docs/concepts/workloads/pods/) specification or in a [container image](https://kubernetes.io/docs/reference/glossary/?all=true#term-image). Using a Secret means that you don't need to include confidential data in your application code.

Because Secrets can be created independently of the Pods that use them, there is less risk of the Secret (and its data) being exposed during the workflow of creating, viewing, and editing Pods. Kubernetes, and applications that run in your cluster, can also take additional precautions with Secrets, such as avoiding writing sensitive data to nonvolatile storage.

## Task 2:

* Create a Secret for your Deployment
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703270901153/afffe55e-2014-4d77-8030-9b38e7ad7a33.png align="center")
    
* Create a Secret for your Deployment using a file or the command line
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703270925840/dbe20c0a-5fab-4664-ade6-e633e86cc186.png align="center")
    
* Update the deployment.yml file to include the Secret
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703271864380/a6500766-772e-48a7-9f34-809afa0c5460.png align="center")
    
* Apply the updated deployment using the command: `kubectl apply -f deployment.yml -n <namespace-name>`
    
* Verify that the Secret has been created by checking the status of the Secrets in your Namespace.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703271903965/a2141f86-496d-4407-a33f-16808ed2f465.png align="center")
    

Thanks for read my blog if you liked it this blog please like and commend.

Contact me on [**linkedin**](http://www.linkedin.com/in/pradeep-chitroliya-9347a9147)

check out my GitHub for more resource [**GitHub**](https://github.com/ChitrolyaPradeep)
