Configuring a Deployment to Use a ConfigMap

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Configure a deployment to use a ConfigMap

Configure a Deployment to Use a ConfigMap

Business Scenario

You want to deploy an application to SAP BTP, Kyma runtime, which needs to be configured with some environment variables. You want to store these environment variables in a ConfigMap and inject them into your application.

Exercise Options

You can perform this exercise in two ways:

  1. Platform Simulation – follow the step-by-step instructions within the simulation.
  2. Live Environment - by using the instructions provided below, you can perform the steps in the SAP BTP Free Tier account.
Note
We strongly recommend first performing the steps in the Live Environment.

Platform Simulation

Choose the Start Exercise button below to open a simulation of the platform. Then follow the step-by-step instructions to configure a deployment to use a ConfigMap.

Live Environment

In this exercise, you will perform the following steps:

  1. Create a ConfigMap.
  2. Deploy an application with the ConfigMap and verify the result.

Prerequisites

  • You have successfully created a SAP BTP, Kyma runtime instance in the SAP BTP subaccount.
  • You have configured kubectl to work with your SAP BTP, Kyma runtime instance.

Result

In this exercise, you have created a ConfigMap and deployed an application that uses the ConfigMap. Furthermore, you have verified that the application is using the ConfigMap correctly.

Further Reading

Task 1: Create a ConfigMap

Steps

  1. Create a ConfigMap.

    1. Create a new file called config-map.yaml to specify your first name and a greeting message:

      Code snippet
      apiVersion: v1
      kind: ConfigMap
      metadata:
        name: name-greeting
      data:
          GREETING: "Hello"
          FIRSTNAME: "Kyma"
      Copy code
    2. Apply the ConfigMap via kubectl.

      Code snippet
      kubectl apply -f config-map.yaml
      Copy code
    3. Check if the ConfigMap has been created:

      Code snippet
      kubectl get configmaps
      Copy code

Task 2: Deploy an application with the ConfigMap and verify the result

Steps

  1. Deploy an application with the ConfigMap.

    1. Create a new file called deployment.yaml to specify your deployment:

      Code snippet
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: test-configmap
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: test-configmap
        template:
          metadata:
            labels:
              app: test-configmap
          spec:
            containers:
            - name: test-configmap
              image: bash
              envFrom:
              - configMapRef:
                  name: name-greeting
              command: ["echo"]
              args: ["$(GREETING) $(FIRSTNAME)!"]
      Copy code
    2. Apply the deployment via kubectl.

      Code snippet
      kubectl apply -f deployment.yaml
      Copy code
    3. Get the pod name.

      Code snippet
      kubectl get pods -l app=test-configmap
      Copy code
    4. Get the output of the pod.

      Code snippet
      kubectl logs <pod-name>
      Copy code

      Alternatively, you could also retrieve the logs via the label selector:

      Code snippet
      kubectl logs -l app=test-configmap
      Copy code

    5. Delete the deployment

      Code snippet
      kubectl delete deployment test-configmap
      Copy code

Result

In this exercise, you have created a ConfigMap and deployed an application that uses the ConfigMap. Furthermore, you have verified that the application is using the ConfigMap correctly.

Further Reading

Log in to track your progress & complete quizzes