ConfigMaps 생성

 

  • Literal : kubectl create configmap dev map from literal=A=10 from literal=B=20 - 문자 그대로 입력
  • file : kubectl create configmap dev map from file=f1 from file=new=f2 - f1, f2 파일에서 입력
  • dir : kubectl create configmap dev map from file= dir -  Configmaps를 만들어 3가지 유형으로 값을 입력 할 수 있다. 

1. ConfigMap 의 Key value 전달 방법 Literal 

root@ip-172-31-4-27:~/pv# kubectl create configmap dev-map --from-literal=A=10 --from-literal=B=20
configmap/dev-map created
root@ip-172-31-4-27:~/pv# kubectl get configmaps dev-map -o yaml
apiVersion: v1
data:
  A: "10"
  B: "20"
kind: ConfigMap
metadata:
  creationTimestamp: "2020-12-02T07:24:46Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:data:
        .: {}
        f:A: {}
        f:B: {}
    manager: kubectl-create
    operation: Update
    time: "2020-12-02T07:24:46Z"
  name: dev-map
  namespace: default
  resourceVersion: "219077"
  selfLink: /api/v1/namespaces/default/configmaps/dev-map
  uid: 757fd93b-eac3-4341-8e91-d731809cf4aa

2. ConfigMap 의 Key value 전달 방법 file

root@ip-172-31-4-27:~/pv# kubectl get configmaps dev-map-1 -o yaml
apiVersion: v1
data:
  f1: |
    first
  new: |
    second
kind: ConfigMap
metadata:
  creationTimestamp: "2020-12-02T07:26:42Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:data:
        .: {}
        f:f1: {}
        f:new: {}
    manager: kubectl-create
    operation: Update
    time: "2020-12-02T07:26:42Z"
  name: dev-map-1
  namespace: default
  resourceVersion: "219410"
  selfLink: /api/v1/namespaces/default/configmaps/dev-map-1
  uid: d4daaa0c-4f65-46c5-9b42-cb7c89b77008

3. ConfigMap 의 Key value 전달 방법 dir

root@ip-172-31-4-27:~/pv/d1# cat > key1
1
root@ip-172-31-4-27:~/pv/d1# cat > key2
2
root@ip-172-31-4-27:~/pv/d1# cat > key3
3
root@ip-172-31-4-27:~/pv/d1# kubectl create configmap dev-map-2 --from-file=d1
error: error reading d1: no such file or directory
root@ip-172-31-4-27:~/pv/d1# cd ..
root@ip-172-31-4-27:~/pv# kubectl create configmap dev-map-2 --from-file=d1
configmap/dev-map-2 created
root@ip-172-31-4-27:~/pv# kubectl create configmap dev-map-2 --from-file=d1^C
root@ip-172-31-4-27:~/pv# kubectl get configmaps dev-map-2 -o yaml
apiVersion: v1
data:
  key1: |
    1
  key2: |
    2
  key3: |
    3
kind: ConfigMap
metadata:
  creationTimestamp: "2020-12-02T07:29:21Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:data:
        .: {}
        f:key1: {}
        f:key2: {}
        f:key3: {}
    manager: kubectl-create
    operation: Update
    time: "2020-12-02T07:29:21Z"
  name: dev-map-2
  namespace: default
  resourceVersion: "219857"
  selfLink: /api/v1/namespaces/default/configmaps/dev-map-2
  uid: 8f0ccb26-0044-421a-8c0f-bae7b0ec8c78

root@ip-172-31-4-27:~/pv# kubectl get cm
NAME        DATA   AGE
dev-map     2      5m33s
dev-map-1   2      3m37s
dev-map-2   3      58s

'클라우드 컴퓨팅 & NoSQL > k8s' 카테고리의 다른 글

DaemonSetController  (0) 2020.12.03
Scheduler  (0) 2020.12.02
Storage Class  (0) 2020.12.02
Volumes (PV와 PVS)  (0) 2020.12.02
Volumes (pod 내 공유 방법, Pod 외부 공유 방법, NFS)  (0) 2020.12.02

+ Recent posts