You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 16 Next »
https://foxutech.medium.com/about-configmap-in-kubernetes-b6b9c0918ac2
Volume 사용:
envFrom:
valueFrom:
https://dev-k8sref-io.web.app/docs/config-and-storage/configmap-v1/
apiVersion: v1
kind: ConfigMap
metadata (ObjectMeta)
data (map[string]string)
immutable (boolean)
apiVersion: v1 kind: ConfigMap metadata: name: game-demo data: # 속성과 비슷한 키; 각 키는 간단한 값으로 매핑됨 player_initial_lives: "3" ui_properties_file_name: "user-interface.properties" # 파일과 비슷한 키 game.properties: | enemy.types=aliens,monsters player.maximum-lives=5 user-interface.properties: | color.good=purple color.bad=yellow allow.textmode=true
apiVersion: v1 kind: Pod metadata: name: configmap-demo-pod spec: containers: - name: demo image: alpine command: ["sleep", "3600"] env: # 환경 변수 정의 - name: PLAYER_INITIAL_LIVES # 참고로 여기서는 컨피그맵의 키 이름과 # 대소문자가 다르다. valueFrom: configMapKeyRef: name: game-demo # 이 값의 컨피그맵. key: player_initial_lives # 가져올 키. - name: UI_PROPERTIES_FILE_NAME valueFrom: configMapKeyRef: name: game-demo key: ui_properties_file_name volumeMounts: - name: config mountPath: "/config" readOnly: true volumes: # 파드 레벨에서 볼륨을 설정한 다음, 해당 파드 내의 컨테이너에 마운트한다. - name: config configMap: # 마운트하려는 컨피그맵의 이름을 제공한다. name: game-demo # 컨피그맵에서 파일로 생성할 키 배열 items: - key: "game.properties" path: "game.properties" - key: "user-interface.properties" path: "user-interface.properties"
sansae@sansaeAir15m2 k8s-lab-workspace % k apply -f configmap.yaml configmap/game-demo created sansae@sansaeAir15m2 k8s-lab-workspace % k get cm NAME DATA AGE game-demo 4 12s kube-root-ca.crt 1 2d10h sansae@sansaeAir15m2 k8s-lab-workspace % k apply -f configmap-pod.yaml pod/configmap-demo-pod created sansae@sansaeAir15m2 k8s-lab-workspace % k exec -it configmap-demo-pod -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=configmap-demo-pod UI_PROPERTIES_FILE_NAME=user-interface.properties PLAYER_INITIAL_LIVES=3 KUBERNETES_SERVICE_PORT=443 KUBERNETES_SERVICE_PORT_HTTPS=443 KUBERNETES_PORT=tcp://10.0.0.1:443 KUBERNETES_PORT_443_TCP=tcp://10.0.0.1:443 KUBERNETES_PORT_443_TCP_PROTO=tcp KUBERNETES_PORT_443_TCP_PORT=443 KUBERNETES_PORT_443_TCP_ADDR=10.0.0.1 KUBERNETES_SERVICE_HOST=10.0.0.1 TERM=xterm HOME=/root