Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

22.6. Downward API를 사용하여 ConfigMap 사용

Pod를 생성할 때 이미지 및 애플리케이션 작성자가 특정 환경에 대한 이미지를 생성할 수 있도록 Downward API를 사용하여 ConfigMap 값을 삽입할 수 있습니다.

22.6.1. 환경 변수 사용

  1. configmap.yaml 파일을 생성합니다.

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: myconfigmap
    data:
      mykey: myvalue
  2. configmap.yaml 파일에서 ConfigMap 을 생성합니다.

    oc create -f configmap.yaml
  3. ConfigMap 을 참조하는 pod.yaml 파일을 생성합니다.

    apiVersion: v1
    kind: Pod
    metadata:
      name: dapi-env-test-pod
    spec:
      containers:
        - name: env-test-container
          image: gcr.io/google_containers/busybox
          command: [ "/bin/sh", "-c", "env" ]
          env:
            - name: MY_CONFIGMAP_VALUE
              valueFrom:
                configMapKeyRef:
                  name: myconfigmap
                  key: mykey
      restartPolicy: Never
  4. pod.yaml 파일에서 Pod를 생성합니다.

    $ oc create -f pod.yaml
  5. 컨테이너의 로그에 MY_CONFIGMAP_VALUE 값이 있는지 확인합니다.

    $ oc logs -p dapi-env-test-pod