K8s env configMapKeyRef.optional

Jmnote (토론 | 기여)님의 2022년 1월 3일 (월) 19:50 판 (→‎개요)

1 개요

k8s configMapKeyRef.optional
a.yaml
apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
  - name: test-container
    image: k8s.gcr.io/busybox
    command: [ "/bin/sh", "-c", "env" ]
    env:
    - name: SPECIAL_LEVEL_KEY
      valueFrom:
        configMapKeyRef:
          name: special-config
          key: SPECIAL_LEVEL
    - name: SPECIAL_TYPE_KEY
      valueFrom:
        configMapKeyRef:
          name: special-config
          key: SPECIAL_TYPE
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
  namespace: default
data:
  SPECIAL_LEVEL: very
  #SPECIAL_TYPE: charm
$ kubectl apply -f a.yaml
pod/dapi-test-pod created
configmap/special-config created
$ kubectl get pod dapi-test-pod
NAME            READY   STATUS                       RESTARTS   AGE
dapi-test-pod   0/1     CreateContainerConfigError   0          97s
a.yaml
apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
  - name: test-container
    image: k8s.gcr.io/busybox
    command: [ "/bin/sh", "-c", "env" ]
    env:
    - name: SPECIAL_LEVEL_KEY
      valueFrom:
        configMapKeyRef:
          name: special-config
          key: SPECIAL_LEVEL
    - name: SPECIAL_TYPE_KEY
      valueFrom:
        configMapKeyRef:
          name: special-config
          key: SPECIAL_TYPE
          optional: true
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
  namespace: default
data:
  SPECIAL_LEVEL: very
  #SPECIAL_TYPE: charm
$ kubectl delete -f a.yaml; kubectl apply -f a.yaml
pod "dapi-test-pod" deleted
configmap "special-config" deleted
pod/dapi-test-pod created
configmap/special-config created
$ kubectl get pod dapi-test-pod
NAME            READY   STATUS             RESTARTS   AGE
dapi-test-pod   0/1     CrashLoopBackOff   3          67s
$ kubectl logs dapi-test-pod | grep SPECIAL
SPECIAL_LEVEL_KEY=very

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}