Part 1: Using ConfigMaps
This is Part 1 of a multi-part, self-paced quick start exercise.
Note
This exercise requires MicroK8s and uses alias kubectl='microk8s kubectl'
. If you do not have these already installed and running, see "Prerequisites".
What Will You Do¶
In part 1, you will:
- Use a ConfigMap to store a key-value pair.
Estimated Time
Estimated time for this exercise is 5 minutes. Watch a video of the exercise below.
Using ConfigMaps¶
A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume.
ConfigMap YAML file¶
Create a configmap using a YAML file, which is a configuration file. You could create a YAML file from the command line, but for this exercise, you can just use a text editor. Or you can download the configmap YAML file from this public Git repository.
- Open the Terminal.
- Navigate to the Downloads folder.
cd ./Downloads
- Use the following command to create an empty YAML file in your Downloads folder.
touch configmap.yaml
- Use the nano text editor in the Terminal.
nano configmap.yaml
- Copy and paste the configuration below into the text editor.
- Press Cmd + X, then type Y and press Return to save the configmap.yaml file.
- Open the command prompt.
- Navigate to the Downloads folder.
cd ./Downloads
- Use the following command to create an empty YAML file in your Downloads folder.
copy NUL configmap.yaml
- Open the configmap.yaml file with a text editor. For example, use Notepad++ to edit the YAML file.
- Copy and paste the configuration below into the text editor.
- Save the configmap.yaml file.
- Open the Terminal.
- Navigate to the Downloads folder.
cd ./Downloads
- Use the following command to create an empty YAML file in your Downloads folder.
touch configmap.yaml
- Use the nano text editor in the Terminal.
nano configmap.yaml
- Copy and paste the configuration below into the text editor.
- Press Ctrl + X, then type Y and press Enter to save the configmap.yaml file.
Add a ConfigMap¶
- In the Terminal or Command Prompt, add the configmap to your environment using a YAML file.
kubectl create -f configmap.yaml
- List the configmaps.
kubectl get configmaps
configmap.yaml¶
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
labels:
app: mysql
data:
MYSQL_DB: mysqldb