In this section, I’ll guide you through each step of setting up ConfigMaps in Kubernetes using the provided Make commands. This breakdown will clarify the process and demonstrate how to manage configurations effectively.
Before we begin, make sure you have the following set up on your computer:
- Docker
- Kind (Kubernetes in Docker)
If you haven’t installed these tools yet, don’t worry! Check out the links in the video description for my tutorials on installing them on Windows, Mac, and Ubuntu.
Step 1: Create a Kind Cluster
Make Command:
make create-cluster
- Description: This command creates a new Kind (Kubernetes in Docker) cluster named
configmap
using the specified configuration file (kind/kind-config.yaml
). This sets up the Kubernetes environment needed for the demo.
Step 2: Create ConfigMap with Literal Value
Make Command:
make create-configmap-literal
- Description: This command creates a ConfigMap named
literal
that stores a single literal valueenv=ConfigMap
. This is useful for setting environment variables directly within your Pods.
Step 3: Create ConfigMap from File
Make Command:
make create-configmap-file
- Description: This command creates a ConfigMap named
file
from theconfig.json
file in your current directory. This is useful for managing larger configuration files that your application may require.
Step 4: Create ConfigMap with Literal and File
Make Command:
make create-configmap
- Description: This command creates a ConfigMap named
password
using both a literal value and theconfig.json
file. The--dry-run=client -o yaml
flags output the ConfigMap definition in YAML format to a file namedconfig-map-literal-file.yaml
, allowing you to review or modify it before applying.
Step 5: Apply the ConfigMap to the Cluster
Make Command:
make apply-configmap
- Description: This command applies the previously created ConfigMap from
config-map-literal-file.yaml
to the Kubernetes cluster, making it available for your Pods.
Step 6: List All ConfigMaps
Make Command:
make list-configmap
- Description: This command lists all ConfigMaps in the current namespace, allowing you to verify that your ConfigMap has been created successfully.
Step 7: Show Detailed Information about a Specific ConfigMap
Make Command:
make show-configmap
- Description: This command retrieves and displays detailed information about the
password
ConfigMap in YAML format, which helps you verify its contents.
Step 8: Apply a Pod Definition
Make Command:
make apply-pod
- Description: This command applies a Pod definition from a
pod.yaml
file. This is where your application will run, and it will use the ConfigMap we created earlier.
Step 9: List All Pods
Make Command:
make list-pods
- Description: This command lists all Pods in the current namespace along with additional information, allowing you to see the status and details of your running Pods.
Step 10: Show Environment Variables of the Pod
Make Command:
make show-pod-env
- Description: This command executes a command inside the
password-generator-app
Pod to list its environment variables. It filters the output to show only the variableENV
, helping you verify the configuration.
Step 11: Show Contents of a File within the Pod
Make Command:
make show-pod-file
- Description: This command lists and displays the contents of the
config.json
file located at/config/config.json
inside thepassword-generator-app
Pod. This is useful for verifying that your application has access to the configuration file.
Step 12: Delete the Kind Cluster
Make Command:
make delete-all
- Description: This command deletes the Kind cluster named
configmap
, cleaning up the resources created during the demo.
By following these steps with the corresponding Make commands, you can effectively set up and manage ConfigMaps in your Kubernetes environment. Each command plays a crucial role in streamlining your application’s configuration management process. If you have any questions or need further assistance, feel free to reach out!