Day 35: Mastering ConfigMaps and Secrets in Kubernetes๐Ÿ”’๐Ÿ”‘๐Ÿ›ก๏ธ

Day 35: Mastering ConfigMaps and Secrets in Kubernetes๐Ÿ”’๐Ÿ”‘๐Ÿ›ก๏ธ

ยท

3 min read

๐Ÿ™ Introduction:

In this blog, we will explore Kubernetes (k8s) concepts ConfigMaps and Secrets.ConfigMaps and Secrets are used to store configuration data and secrets, respectively.

What are ConfigMaps and Secrets in Kubernetes (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

  1. 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).

  2. 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! ๐Ÿš€

๐Ÿ’ผTask: 1

  • Create a ConfigMap for your Deployment

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

  • Update the deployment.yml file to include the ConfigMap

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

  • Verify that the ConfigMap has been created by checking the status of the ConfigMaps in your Namespace.

Steps :

  1. Create a ConfigMap for your Deployment
apiVersion: v1
kind: ConfigMap
metadata:i
  name: todo-config
data:
  DATABASE_URL: "your_database_url"
  API_KEY: "your_api_key"

  1. Apply the ConfigMap file
kubectl apply -f configmap.yml -n todo-namespace
  1. Update your Deployment YAML file to include the ConfigMap
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: 'sutish/django-todo:latest'
          ports:
            - containerPort: 8000
          envFrom:
            - configMapRef:
                name: todo-config
  1. Apply the updated deployment file
kubectl apply -f deployment.yml -n todo-namespace

  1. Verify that the ConfigMap has been created
kubectl get configmaps -n todo-namespace

๐Ÿ’ผTask: 2

  • Create a Secret for your Deployment

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

  • Update the deployment.yml file to include the Secret

  • 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.

Steps :

  1. Create a Secret for your Deployment
apiVersion: v1
kind: Secret
metadata:
  name: dotfile-secret
type: Opaque
data:
  .secret-file: dmFsdWUtMg0KDQo=

  1. Apply the secret file
kubectl apply -f secret.yml -n todo-namespace

  1. Update your Deployment YAML file to include the ConfigMap
apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-deployment
  labels:
    app: todo-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: todo-app
  template:
    metadata:
      labels:
        app: todo-app
    spec:
      containers:
        - name: todo-app
          image: 'sutish/django-todo:latest'
          ports:
            - containerPort: 8000
          envFrom:
            - secretRef:
                name: dotfile-secret

  1. Apply the updated deployment file
kubectl apply -f deployment.yml -n todo-namespace

  1. Verify that the ConfigMap has been created
kubectl get secrets -n todo-namespace

๐Ÿ‘‹ Conclusion :

In this blog, we cover ConfigMaps and Secrets in Kubernetes & apply those to the deployment file. In the next blog, we will cover some advanced topics.

Thank you for reading!

Contact me on Linkedin ๐Ÿค

Check out my GitHub for more resources ๐Ÿ“š

ย