이 페이지에서는 Compute Engine 영구 디스크와 같은 외부 저장소 하드웨어를 Google Kubernetes Engine(GKE) 워크로드의 임시 볼륨으로 사용하는 방법을 보여줍니다. Kubernetes 볼륨 및 StorageClasses에 대해 이미 숙지하고 있어야 합니다.
Kubernetes에서 임시 스토리지를 사용해야 하는 경우
임시 스토리지는 데이터 처리 파이프라인, 머신러닝 작업, 일괄 처리, 로컬 캐싱, 분석 등 애플리케이션 수명 주기 동안 워크로드에 데이터만 필요한 경우에 유용합니다.
기본적으로 GKE 노드 부팅 디스크의 일부는 포드에서 임시 스토리지로 사용 가능합니다. 이 방법을 사용하려면 공간 계획을 신중하게 계획해야 하는 경우가 많습니다.
Kubernetes 일반 임시 볼륨은 PersistentVolumeClaims를 사용하여 포드에 대한 임시 스토리지를 명시적으로 요청할 수 있습니다. GKE는 Compute Engine Persistent Disk를 동적으로 프로비저닝하고 디스크를 노드에 연결합니다. 이런 유형의 임시 스토리지는 다음과 같은 상황에서 유용합니다.
워크로드의 성능 요구사항이 높으므로 스토리지 하드웨어를 제어해야 하는 경우
컨테이너별 단기 임시 스토리지가 필요한 경우
emptyDir을 사용하여 임시 스토리지를 프로비저닝하는 것을 피하고자 하는 경우. emptyDir 볼륨은 여러 컨테이너가 임시 스토리지의 데이터를 공유하려는 상황에서 여전히 유용합니다.
GKE 기본 제공 기본값보다 더 많은 임시 스토리지 용량을 원하는 경우
Standard 모드 GKE 클러스터에 대해 노드 부팅 디스크 크기와 유형을 미리 계획하는 것을 피하고자 하는 경우
GKE의 임시 스토리지 유형
일반적으로 부팅 디스크 스토리지 용량 또는 전용 Persistent Disk를 포드 및 컨테이너의 임시 스토리지로 사용할 수 있습니다. 다음 표에서 차이점을 확인하세요.
이 태스크에 Google Cloud CLI를 사용하려면 gcloud CLI를 설치한 후 초기화합니다. 이전에 gcloud CLI를 설치한 경우 gcloud components update를 실행하여 최신 버전을 가져옵니다.
버전 1.23 이상을 실행하는 GKE Autopilot 또는 Standard 클러스터가 있는지 유의하세요.
Google Cloud 프로젝트에 스토리지 하드웨어를 위한 충분한 할당량이 있는지 확인하세요. 할당량을 관리하려면 프로젝트의 할당량 보기를 살펴보세요.
StorageClass 만들기
커스텀 Kubernetes StorageClass를 만들면 가격 및 성능 요구사항에 따라 프로비저닝할 스토리지 유형을 지정할 수 있습니다. 이 단계는 선택사항이지만 권장됩니다. pd-balanced 영구 디스크 유형이 있는 GKE 기본 StorageClass를 사용하려면 이 단계를 건너뜁니다.
이 매니페스트는 다음 속성을 사용해서 ephemeral-volume이라는 새 PersistentVolume을 요청하는 새 Kubernetes PersistentVolumeClaim을 만듭니다.
spec.volumes.ephemeral:ephemeral 볼륨 유형입니다.
.spec.accessModes: 볼륨 액세스 모드로, 포드의 읽기/쓰기 액세스 권한과 노드 간의 볼륨 공유를 결정합니다. 이 예시에서는 노드에서 하나 이상의 포드가 액세스할 수 있도록 PersistentVolume을 마운트하는 ReadWriteOnce을 사용합니다. 자세한 내용은 액세스 모드를 참조하세요.
.spec.storageClassName: 생성한 StorageClass의 이름(선택사항) 이 필드를 생략하면 GKE는 기본 StorageClass를 사용하여 pd-balanced Persistent Disk를 프로비저닝합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-11-25(UTC)"],[],[],null,["# Use dedicated Persistent Disks as ephemeral volumes\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nThis page shows you how to use external storage hardware, such as\nCompute Engine Persistent Disks, as ephemeral volumes in your\nGoogle Kubernetes Engine (GKE) workloads. You should already be familiar with\nKubernetes\n[Volumes](https://kubernetes.io/docs/concepts/storage/volumes/)\nand [StorageClasses](https://kubernetes.io/docs/concepts/storage/storage-classes/).\n\nWhen to use ephemeral storage in Kubernetes\n-------------------------------------------\n\nEphemeral storage is useful in any situation where your workloads only need the\ndata during the lifecycle of the application, such as for data-processing\npipelines, machine learning jobs, batch processing, local caching, or analytics.\nBy default, part of the GKE node boot disk is available to use as\nephemeral storage in your Pods. This approach often requires careful space planning.\n\nKubernetes\n[*generic ephemeral volumes*](https://kubernetes.io/docs/concepts/storage/ephemeral-volumes/#generic-ephemeral-volumes)\nlet you explicitly request ephemeral\nstorage for your Pods by using PersistentVolumeClaims. GKE\ndynamically provisions Compute Engine\n[Persistent Disks](/compute/docs/disks/persistent-disks) and attaches\nthe disks to your nodes. This type of ephemeral storage is useful in situations\nlike the following:\n\n- Your workloads have high performance requirements, so you need to control the storage hardware.\n- You need short-term, container-specific ephemeral storage.\n- You want to avoid using `emptyDir` to provision ephemeral storage. `emptyDir` volumes are still useful in situations where you want multiple containers to share the data in the ephemeral storage.\n- You want more ephemeral storage capacity than the GKE built-in defaults.\n- You want to avoid having to plan your node boot disk size and type in advance for Standard mode GKE clusters.\n\nEphemeral storage types in GKE\n------------------------------\n\nIn general, you can use boot disk storage capacity or dedicated\nPersistent Disks as ephemeral storage in your Pods and containers. The\nfollowing table describes the differences:\n\nPricing\n-------\n\nStorage that you provision through generic ephemeral volumes as described in\nthis guide is billed based on [Compute Engine disk pricing](/compute/all-pricing#disk).\n\nBefore you begin\n----------------\n\nBefore you start, make sure that you have performed the following tasks:\n\n- Enable the Google Kubernetes Engine API.\n[Enable Google Kubernetes Engine API](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com)\n- If you want to use the Google Cloud CLI for this task, [install](/sdk/docs/install) and then [initialize](/sdk/docs/initializing) the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running `gcloud components update`. **Note:** For existing gcloud CLI installations, make sure to set the `compute/region` [property](/sdk/docs/properties#setting_properties). If you use primarily zonal clusters, set the `compute/zone` instead. By setting a default location, you can avoid errors in the gcloud CLI like the following: `One of [--zone, --region] must be supplied: Please specify location`. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.\n\n\u003c!-- --\u003e\n\n- Ensure that you have a GKE Autopilot or Standard cluster running version 1.23 or later.\n- Ensure that you have enough quota in your Google Cloud project for the storage hardware. To manage your quota, see [View and manage quotas](/docs/quotas/view-manage).\n\nCreate a StorageClass\n---------------------\n\nCreating a custom Kubernetes StorageClass lets you specify the type of storage\nto provision based on your price and performance requirements. This step is\noptional but recommended. If you want to use the GKE default\nStorageClass, which has the `pd-balanced` Persistent Disk type, skip this step.\n\n1. Save the following manifest as `ephemeral-pd-class.yaml`:\n\n apiVersion: storage.k8s.io/v1\n kind: StorageClass\n metadata:\n name: ephemeral-ssd\n provisioner: pd.csi.storage.gke.io\n volumeBindingMode: WaitForFirstConsumer\n allowVolumeExpansion: true\n parameters:\n type: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eSTORAGE_TYPE\u003c/span\u003e\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eSTORAGE_TYPE\u003c/var\u003e with the name of the\n Persistent Disk type that you want, like `pd-ssd`. For a list of\n supported types, see [Persistent Disk types](/compute/docs/disks/persistent-disks#disk-types)\n in the Compute Engine documentation.\n2. Create the StorageClass:\n\n kubectl create -f ephemeral-pd-class.yaml\n\nRequest ephemeral storage capacity in a Pod\n-------------------------------------------\n\nTo provision, attach, and use external hardware as ephemeral storage, add the\ncorresponding volume to your Pod manifest and add a volume mount to the container\nspecification.\n\n1. Save the following manifest as `ephemeral-ssd-deployment.yaml`:\n\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: ephemeral-deployment\n spec:\n replicas: 1\n selector:\n matchLabels:\n storage: ephemeral\n template:\n metadata:\n labels:\n storage: ephemeral\n spec:\n containers:\n - name: ephemeral-container\n image: nginx\n resources:\n requests:\n cpu: 500m\n memory: 2Gi\n ephemeral-storage: 2Gi\n volumeMounts:\n - mountPath: \"/short-term\"\n name: ephemeral-volume\n volumes:\n - name: ephemeral-volume\n ephemeral:\n volumeClaimTemplate:\n metadata:\n labels:\n type: ephemeral\n spec:\n accessModes: \\[\"ReadWriteOnce\"\\]\n storageClassName: \"ephemeral-ssd\"\n resources:\n requests:\n storage: 1Ti\n\n This manifest creates a new Kubernetes PersistentVolumeClaim that\n requests a new PersistentVolume named `ephemeral-volume` with the following\n properties:\n - **`spec.volumes.ephemeral`:** The `ephemeral` volume type.\n - **`.spec.accessModes`:** The volume access mode, which determines read-write access from Pods and volume sharing between nodes. This examples uses `ReadWriteOnce`, which mounts the PersistentVolume to a single node for access by one or more Pods on the node. For details, see [Access modes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes).\n - **`.spec.storageClassName`:** Optionally, the name of the StorageClass that you created. If you omit this field, GKE uses the default StorageClass and provisions a `pd-balanced` Persistent Disk.\n - **`.spec.resources.requests.storage`:** The storage capacity that you want.\n2. Create the Deployment:\n\n kubectl create -f ephemeral-ssd-deployment.yaml\n\nGKE provisions a Compute Engine disk that meets the\nrequirements of the PersistentVolumeClaim and attaches the disk to the node.\nGKE mounts the volume into the Pod and provides the requested capacity\nto the container.\n\nVerify that GKE mounted an ephemeral volume\n-------------------------------------------\n\n1. Create a shell session in the Pod:\n\n kubectl exec -it deploy/ephemeral-deployment -- bash\n\n2. Check the mounted volumes:\n\n df -h\n\n The output is similar to the following: \n\n Filesystem Size Used Available Use% Mounted on\n ...\n /dev/sdb 1006.9G 28.0K 1006.8G 0% /short-term\n /dev/sda1 94.3G 3.6G 90.6G 4% /etc/hosts\n /dev/sda1 94.3G 3.6G 90.6G 4% /dev/termination-log\n /dev/sda1 94.3G 3.6G 90.6G 4% /etc/hostname\n /dev/sda1 94.3G 3.6G 90.6G 4% /etc/resolv.conf\n ...\n\n3. Exit the shell session:\n\n exit\n\n| **Success:** You dynamically provisioned external storage hardware and mounted it to your Kubernetes workload as ephemeral storage.\n\nWhat's next\n-----------\n\n- [Learn about the available storage options in GKE](/kubernetes-engine/docs/concepts/storage-overview)"]]