본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

볼륨 마운트

원문 보기 위키 갱신

(/workspace 볼륨 외에) pod 컨테이너의 일부 또는 전체에 추가 볼륨 마운트를 연결할 수 있어요. 이는 추가 볼륨으로 마운트되는 git mirrors를 사용할 때 유용할 수 있어요.

출처: 문서

본문

모든 컨테이너(checkout, agent, command, sidecar 등)에 추가 볼륨 마운트를 연결하려면 kubernetes 플러그인을 사용할 수 있어요. 예를 들면:

steps:
  - label: ":file_cabinet: Share file across containers using volume mount"
    key: share-file-using-scratch-volume
    env:
      SCRATCH_VOLUME_PATH: "/tmp/scratch"
      SCRATCH_VOLUME_PATH_TIMEOUT_SECONDS: "10"
    plugins:
      - kubernetes:
          podSpec:
            containers:
              - image: alpine:latest
                command:
                  - touch $${SCRATCH_VOLUME_PATH}/foo-$${BUILDKITE_JOB_ID}.txt
              - image: alpine:latest
                command:
                  - |-
                    COUNT=0
                    until [[ $$((COUNT++)) == $${SCRATCH_VOLUME_PATH_TIMEOUT_SECONDS} ]]; do
                      [[ -f "$${SCRATCH_VOLUME_PATH}/foo-$${BUILDKITE_JOB_ID}.txt" ]] && break
                      echo "⚠️  Waiting for $${SCRATCH_VOLUME_PATH}/foo-$${BUILDKITE_JOB_ID}.txt to be written... (Attempt $${COUNT}/$${SCRATCH_VOLUME_PATH_TIMEOUT_SECONDS})"
                      sleep 1
                    done

                    if ! [[ -f "$${SCRATCH_VOLUME_PATH}/foo-$${BUILDKITE_JOB_ID}.txt" ]]; then
                      echo "⛔ $${SCRATCH_VOLUME_PATH}/foo-$${BUILDKITE_JOB_ID}.txt has not been written"
                      exit 1
                    fi

                    echo "✅ $${SCRATCH_VOLUME_PATH}/foo-$${BUILDKITE_JOB_ID}.txt has been written"
                    rm -f "$${SCRATCH_VOLUME_PATH}/foo-$${BUILDKITE_JOB_ID}.txt"
            volumes:
              - name: scratch-volume
                hostPath:
                  path: "/tmp/volumes/scratch"
                  type: DirectoryOrCreate
          extraVolumeMounts:
            - name: scratch-volume
              mountPath: /tmp/scratch

checkout 컨테이너에만

checkout 컨테이너에만 추가 볼륨을 연결하려면 YAML 설정에서 config.default-checkout-params.extraVolumeMounts를 정의하세요. 예를 들면:

# values.yaml
config:
  default-checkout-params:
    gitCredentialsSecret:
      secretName: my-git-credentials
    extraVolumeMounts:
      - name: checkout-extra-dir
        mountPath: /extra-checkout
  pod-spec-patch:
    containers:
      - name: checkout
        image: "buildkite/agent:latest"
    volumes:
      - name: checkout-extra-dir
        hostPath:
          path: /my/extra/dir/checkout
          type: DirectoryOrCreate

또는 kubernetes 플러그인의 checkout.extraVolumeMounts를 사용해서 할 수도 있어요. 예를 들면:

# pipeline.yml
...
  kubernetes:
    checkout:
      extraVolumeMounts:
        - name: checkout-extra-dir
          mountPath: /extra-checkout
    podSpecPatch:
      containers:
        - name: checkout
          image: "buildkite/agent:latest"
      volumes:
        - name: checkout-extra-dir
          hostPath:
            path: /my/extra/dir/checkout
            type: DirectoryOrCreate

command 컨테이너에만

container-#(command) 컨테이너에만 추가 볼륨을 연결하려면 YAML 설정에서 config.default-command-params.extraVolumeMounts를 정의하세요. 예를 들면:

# values.yaml
config:
  default-command-params:
    extraVolumeMounts:
      - name: command-extra-dir
        mountPath: /extra-command
  pod-spec-patch:
    containers:
      - name: container-0
        image: "buildkite/agent:latest"
    volumes:
      - name: command-extra-dir
        hostPath:
          path: /my/extra/dir/command
          type: DirectoryOrCreate

또는 kubernetes 플러그인의 commandParams.extraVolumeMounts를 사용해서 할 수도 있어요. 예를 들면:

# pipeline.yml
...
  kubernetes:
    commandParams:
      extraVolumeMounts:
        - name: command-extra-dir
          mountPath: /extra-command
    podSpecPatch:
      containers:
        - name: container-0
          image: "buildkite/agent:latest"
      volumes:
        - name: command-extra-dir
          hostPath:
            path: /my/extra/dir/command
            type: DirectoryOrCreate

sidecar 컨테이너에만

sidecar 컨테이너에만 추가 볼륨을 연결하려면 YAML 설정에서 config.default-sidecar-params.extraVolumeMounts를 정의하세요. 예를 들면:

# values.yaml
config:
  default-sidecar-params:
    extraVolumeMounts:
      - name: sidecar-extra-dir
        mountPath: /extra-sidecar
  pod-spec-patch:
    containers:
      - name: checkout
        image: "buildkite/agent:latest"
    volumes:
      - name: sidecar-extra-dir
        hostPath:
          path: /my/extra/dir/sidecar
          type: DirectoryOrCreate

또는 kubernetes 플러그인의 sidecarParams.extraVolumeMounts를 사용해서 할 수도 있어요. 예를 들면:

# pipeline.yml
...
  kubernetes:
    sidecars:
      - image: nginx:latest
    sidecarParams:
      extraVolumeMounts:
        - name: sidecar-extra-dir
          mountPath: /extra-sidecar
    podSpecPatch:
      containers:
        - name: checkout
          image: "buildkite/agent:latest"
      volumes:
        - name: sidecar-extra-dir
          hostPath:
            path: /my/extra/dir/sidecar
            type: DirectoryOrCreate

더 알아보기 (Learn more)