Skip to content

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.


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.

  1. Open the Terminal.
  2. Navigate to the Downloads folder.
    cd ./Downloads
    
  3. Use the following command to create an empty YAML file in your Downloads folder.
    touch configmap.yaml
    
  4. Use the nano text editor in the Terminal.
    nano configmap.yaml
    
  5. Copy and paste the configuration below into the text editor.
  6. Press Cmd + X, then type Y and press Return to save the configmap.yaml file.
  1. Open the command prompt.
  2. Navigate to the Downloads folder.
    cd ./Downloads
    
  3. Use the following command to create an empty YAML file in your Downloads folder.
    copy NUL configmap.yaml
    
  4. Open the configmap.yaml file with a text editor. For example, use Notepad++ to edit the YAML file.
  5. Copy and paste the configuration below into the text editor.
  6. Save the configmap.yaml file.
  1. Open the Terminal.
  2. Navigate to the Downloads folder.
    cd ./Downloads
    
  3. Use the following command to create an empty YAML file in your Downloads folder.
    touch configmap.yaml
    
  4. Use the nano text editor in the Terminal.
    nano configmap.yaml
    
  5. Copy and paste the configuration below into the text editor.
  6. Press Ctrl + X, then type Y and press Enter to save the configmap.yaml file.

Add a ConfigMap

  1. In the Terminal or Command Prompt, add the configmap to your environment using a YAML file.
    kubectl create -f configmap.yaml
    
  2. List the configmaps.
    kubectl get configmaps
    
    Get ConfigMaps

configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-config
  labels:
    app: mysql
data:
  MYSQL_DB: mysqldb