7.2.2. Init Container 생성


initContainers 구성이 포함된 Pod 사양을 생성하여 init 컨테이너를 생성합니다.

다음 예제에서는 두 개의 init 컨테이너가 있는 간단한 Pod를 간략하게 설명합니다. 첫 번째 init 컨티너는 myservice 서비스가 완료될 때까지 기다립니다. 그 후 두 번째는 mydb 서비스가 완료될 때까지 기다립니다. 두 init 컨테이너가 모두 완료되면 Pod가 시작됩니다.

프로세스

  1. Init 컨테이너에 대한 포드를 생성합니다.

    1. 다음과 유사한 YAML 파일을 생성합니다.

      apiVersion: v1
      kind: Pod
      metadata:
        name: myapp-pod
        labels:
          app: myapp
      spec:
        securityContext:
          runAsNonRoot: true
          seccompProfile:
            type: RuntimeDefault
        containers:
        - name: myapp-container
          image: registry.access.redhat.com/ubi9/ubi:latest
          command: ['sh', '-c', 'echo The app is running! && sleep 3600']
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop: [ALL]
        initContainers:
        - name: init-myservice
          image: registry.access.redhat.com/ubi9/ubi:latest
          command: ['sh', '-c', 'until getent hosts myservice; do echo waiting for myservice; sleep 2; done;']
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop: [ALL]
        - name: init-mydb
          image: registry.access.redhat.com/ubi9/ubi:latest
          command: ['sh', '-c', 'until getent hosts mydb; do echo waiting for mydb; sleep 2; done;']
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop: [ALL]
    2. 다음 명령을 사용하여 Pod를 생성합니다.

      $ oc create -f myapp.yaml
    3. 다음 명령을 사용하여 Pod의 상태를 확인합니다.

      $ oc get pods

      출력 예

      NAME                          READY     STATUS              RESTARTS   AGE
      myapp-pod                     0/1       Init:0/2            0          5s

      포드 상태 Init:0/2 는 두 서비스를 기다리고 있음을 나타냅니다.

  2. myservice 서비스를 생성합니다.

    1. 다음과 유사한 YAML 파일을 생성합니다.

      kind: Service
      apiVersion: v1
      metadata:
        name: myservice
      spec:
        ports:
        - protocol: TCP
          port: 80
          targetPort: 9376
    2. 다음 명령을 사용하여 Pod를 생성합니다.

      $ oc create -f myservice.yaml
    3. 다음 명령을 사용하여 Pod의 상태를 확인합니다.

      $ oc get pods

      출력 예

      NAME                          READY     STATUS              RESTARTS   AGE
      myapp-pod                     0/1       Init:1/2            0          5s

      포드 상태 Init:1/2 는 하나의 서비스, 이 경우에는 mydb 서비스를 기다리고 있음을 나타냅니다.

  3. mydb 서비스를 생성합니다.

    1. 다음과 유사한 YAML 파일을 생성합니다.

      kind: Service
      apiVersion: v1
      metadata:
        name: mydb
      spec:
        ports:
        - protocol: TCP
          port: 80
          targetPort: 9377
    2. 다음 명령을 사용하여 Pod를 생성합니다.

      $ oc create -f mydb.yaml
    3. 다음 명령을 사용하여 Pod의 상태를 확인합니다.

      $ oc get pods

      출력 예

      NAME                          READY     STATUS              RESTARTS   AGE
      myapp-pod                     1/1       Running             0          2m

      Pod 상태( 실행 중 )는 더 이상 서비스를 기다리지 않고 실행 중임을 나타냅니다.

Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동