Discovering Kubernetes
Discovering Kyma
Working with Kubernetes Workloads
Using Services to Create Internal and External Communication with Kubernetes
Using Service Meshes with Istio
Using Kyma Eventing
Using Kubernetes Storage and StatefulSets
Using SAP BTP Service Management
Performing Observability and Monitoring
Using ConfigMaps and Secrets

Configuring a Deployment to Use a ConfigMap

Objective

After completing this lesson, you will be able to configure a deployment to use a ConfigMap

Configure a Deployment to Use a ConfigMap

Usage Scenario

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

Task Flow

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

Before you begin, ensure that the following prerequisites are met:

Task 1: Create a ConfigMap

Steps

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

    Code Snippet
    1234567
    apiVersion: v1 kind: ConfigMap metadata: name: name-greeting data: GREETING: "Hello" FIRSTNAME: "Kyma"
  2. Apply the ConfigMap using kubectl.

    Code Snippet
    1
    kubectl apply -f config-map.yaml
  3. Check if the ConfigMap has been created:

    Code Snippet
    1
    kubectl get configmaps

Result

If successful, the printed list contains the name-greeting ConfigMap.

Task 2: Deploy an Application with the ConfigMap

Steps

  1. Create a new file called deployment.yaml that specifies the Deployment configuration:

    YAML
    12345678910111213141516171819202122
    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)!"]
  2. Apply the Deployment using kubectl.

    Code Snippet
    1
    kubectl apply -f deployment.yaml
  3. Get the Pod name.

    Code Snippet
    1
    kubectl get pods -l app=test-configmap
  4. Get the output of the Pod.

    Code Snippet
    1
    kubectl logs <pod-name>

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

    Code Snippet
    1
    kubectl logs -l app=test-configmap

  5. Delete the Deployment.

    Code Snippet
    1
    kubectl delete deployment test-configmap

Result

In this exercise, you have created a ConfigMap and deployed an application that uses the ConfigMap.

Further Reading