Day 35: Mastering ConfigMaps and Secrets in Kubernetes🔒🔑🛡️

Day 35: Mastering ConfigMaps and Secrets in Kubernetes🔒🔑🛡️

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 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! 🚀

Today's task:

  • Create a ConfigMap for your Deployment

  • Create a ConfigMap for your Deployment using a file or the command line

No alt text provided for this image

  • Update the deployment.yml file to include the ConfigMap

  • Apply the updated deployment using the command: kubectl apply -f deployment.yml -n <namespace-name>

      kubectl apply -f configmap.yml
    
  • Verify that the ConfigMap has been created by checking the status of the ConfigMaps in your Namespace.

Here, the environment variable application is included in the pod definition and gets its value from ConfigMap. The key application and the ConfigMap my-config-map are the sources of the value, which is specified in the field value.

Apply the updated deployment using the command

 kubectl apply -f deployment.yml -n <namespace-name>

No alt text provided for this image

This command will display the ConfigMap's metadata, data, and status are in detail.

kubectl describe configmap <configmap-name> -n <namespace-name>

No alt text provided for this image

You can also use the following command to see all the environment variables defined in the pod:

printenv

No alt text provided for this image

Task 2:

Create a Secret for your Deployment

Create a Secret for your Deployment using a file or the command line

create a secret.yml file

The secret's name and other details are included in the metadata section. The type indicates the secret's type, which in this instance is opaque. Put the password in the encrypted format.

Update the deployment.yml file to include the Secret

The deployment definition includes an environment variable env-secret whose value is taken from the secret. The value from the field specifies the source of the value, which is the Secret my-secret and the key password

Apply the updated deployment using the command: kubectl apply -f deployment.yml -n <namespace-name>

No alt text provided for this image

kubectl get secrets -n <namespace-name>

No alt text provided for this image

You can also use the following command to view the details of a specific secret:

kubectl describe secret <secret-name> -n <namespace-name>

No alt text provided for this image

Happy Learning!