Day 19/40 - kubernetes configmap and secret - CKA Full Course 2024

About this video

### Summary of the Video Content: 1. **Introduction**: - The video is part of the "CK 2024" series, specifically Video #19. - The topic focuses on **ConfigMaps** and **Secrets** in Kubernetes. - A hands-on demo is provided, along with a task for viewers to practice in the GitHub repository (Day 19 folder). 2. **Objective of the Video**: - To explain **ConfigMaps** and how they can be used to manage environment variables efficiently. - To demonstrate different methods of creating and injecting ConfigMaps into Pods. - Encourages viewers to engage by liking, commenting, and completing tasks. 3. **Recap of Environment Variables**: - Previously, environment variables were passed directly in the Pod YAML file as key-value pairs. - This approach becomes inefficient when managing multiple Pods or reusable variables, leading to redundancy and inconsistency. 4. **Introduction to ConfigMaps**: - **ConfigMaps** are Kubernetes objects used to externalize configuration data from Pods. - They allow storing key-value pairs outside the Pod definition, promoting reusability and consistency. 5. **Demo: Creating and Using ConfigMaps**: - **Imperative Method**: - Created a ConfigMap using the command: ```bash kubectl create configmap app-cm --from-literal=first_name=value1 --from-literal=last_name=value2 ``` - Verified the ConfigMap using `kubectl get cm` and `kubectl describe cm`. - **Injecting ConfigMap into a Pod**: - Used the `env` block in the Pod YAML to reference the ConfigMap: ```yaml env: - name: USERNAME valueFrom: configMapKeyRef: name: app-cm key: first_name ``` - Applied the YAML file and verified the environment variable inside the Pod using `kubectl exec`. 6. **Alternative Methods for ConfigMap Creation**: - **From File**: For large datasets, store key-value pairs in a file and create the ConfigMap using: ```bash kubectl create configmap app-cm --from-file=app.config ``` - **Declarative Method**: Generate a YAML file using: ```bash kubectl create configmap app-cm --from-literal=key=value --dry-run=client -o yaml > cm.yaml ``` - The YAML file includes fields like `apiVersion`, `kind`, `metadata`, and `data`. 7. **Efficient Injection of ConfigMaps**: - Instead of referencing individual variables, inject all key-value pairs from a ConfigMap using: ```yaml envFrom: - configMapRef: name: app-cm ``` 8. **Mounting ConfigMaps as Volumes**: - ConfigMaps can also be mounted as volumes in a Pod: ```yaml volumeMounts: - name: config-volume mountPath: /etc/config volumes: - name: config-volume configMap: name: app-cm ``` - This method makes the ConfigMap accessible as files within the container. 9. **Updating ConfigMaps**: - Changes to ConfigMaps require either deleting and recreating the Pod or using the `--force` flag during updates. 10. **Secrets Overview**: - Secrets are similar to ConfigMaps but are used for sensitive data (e.g., passwords, tokens). - Will be covered in detail in future videos. 11. **Conclusion**: - Summarized the importance of ConfigMaps for managing configurations efficiently. - Encouraged viewers to complete the hands-on task in the GitHub repository. - Requested engagement through likes, comments, and sharing the video series. - Mentioned upcoming videos and encouraged participation in the Discord community for support. ### Key Takeaways: - **ConfigMaps** help externalize configuration data, improving reusability and maintainability. - Multiple methods exist for creating and injecting ConfigMaps: imperative commands, declarative YAML, and mounting as volumes. - Efficient injection techniques, such as `envFrom`, simplify managing large numbers of environment variables. - Hands-on practice is essential for mastering these concepts.


Course: Certified Kubernetes Administrator Full Course For beginners | CKA 2025

This playlist contains the complete CKA series for beginners, based on the latest 2025 curriculum. It includes 40+ videos with hands-on demos, assignments, and exam-based scenarios. We will cover everything from the basics to the Advanced, including fundamental concepts such as Docker, containers, Docker storage and networking, DNS, etc.

View Full Course