본문 바로가기
ops/kubernetes

configmap 생성하기

by seohan1010 2026. 1. 7.

방법1. 정의 파일로 생성 

#정의파일 생성 
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config-map
data:
  username: admin
  password: password1234

#확인 
kubectl get configmap app-config-map -o yaml 


apiVersion: v1
items:
- apiVersion: v1
  data:
    password: password1234
    username: admin
  kind: ConfigMap
       .
       .
       .

 

방법2. cli에서 생성 

#평문으로 생성 
kubectl create configmap app-config-map \ 
                      --from-literal=username=admin \
                      --from-literal=password=password1234

#확인 
k get configmap -o yaml

apiVersion: v1
items:
- apiVersion: v1
  data:
    password: password1234
    username: admin
  kind: ConfigMap
       .
       .
       .



방법3. 파일로부터 생성 

#파일을 옵션으로 지정 (파일에는 value에 해당하는 값만 작성)
 kubectl create configmap app-config-map \
                        --from-file=username=username.txt \
                        --from-file=password=password.txt
                        
#확인 
kubectl get configmap app-config-map -o yaml 


apiVersion: v1
data:
  password: |
    password1234
  username: |
    admin
kind: ConfigMap
metadata:
          .
          .
          .

 

https://kubernetes.io/docs/reference/kubectl/generated/kubectl_create/kubectl_create_configmap/

 

kubectl create configmap

Synopsis Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basename of the file, and the value wi

kubernetes.io