본문 바로가기

Cloud

(Kubernetes) - application에 data 주입 3

반응형

🍳머리말

container를 위한 환경 변수를 정의하는 설명글입니다. k8s cluster가 구축되어 있어야하며 node는 3개 이상이어야 합니다.


📕container를 위한 환경 변수 정의

📔 설명

 pod를 생성할 때, pod안에서 동작하는 container를 위한 환경 변수를 설정할 수 있습니다. 환경 변수를 설정하려면 구성 file에 env나 envFrom field를 포함시켜야 합니다.

📔 예제

이 예제에서, 한 개의 container를 실행하는 pod를 생성합니다. pod를 위한 구성 file은 DEMO_GREETING 이라는 이름과 "Hello from the environment"이라는 값을 가지는 환경 변수를 정의합니다.

 

envars.yaml

apiVersion: v1
kind: Pod
metadata:
  name: envar-demo
  labels:
    purpose: demonstrate-envars
spec:
  containers:
  - name: envar-demo-container
    image: gcr.io/google-samples/node-hello:1.0
    env:
    - name: DEMO_GREETING
      value: "Hello from the environment"
    - name: DEMO_FAREWELL
      value: "Such a sweet sorrow"

 

apply

kubectl apply -f https://k8s.io/examples/pods/inject/envars.yaml

또는

kubectl apply -f envars.yaml

 

실행 pod 조회

kubectl get pods -l purpose=demonstrate-envars

 

pod의 container 환경 변수 나열

kubectl exec envar-demo -- printenv

📕참조

https://kubernetes.io/ko/docs/tasks/inject-data-application/define-environment-variable-container/

 

컨테이너를 위한 환경 변수 정의하기

본 페이지는 쿠버네티스 파드의 컨테이너를 위한 환경 변수를 정의하는 방법에 대해 설명한다. 시작하기 전에 쿠버네티스 클러스터가 필요하고, kubectl 커맨드-라인 툴이 클러스터와 통신할 수

kubernetes.io