在本快速入门指南中,您将了解如何从 Google Kubernetes Engine (GKE) 应用中访问 Cloud Storage 存储桶,就像它们是本地文件系统一样。本快速入门提供了一个示例 Kubernetes 清单,用于创建 Pod 来装载存储桶,并介绍了如何使用 Pod 的文件系统与存储桶的内容进行交互。
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
In the Principal column, find all rows that identify you or a group that
you're included in. To learn which groups you're included in, contact your
administrator.
For all rows that specify or include you, check the Role column to see whether
the list of roles includes the required roles.
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-01。"],[],[],null,["Quickstart: Access Cloud Storage buckets with the FUSE CSI driver [Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview)\n\n*** ** * ** ***\n\n\u003cbr /\u003e\n\nIn this quickstart guide, you learn how to access Cloud Storage buckets from within\na Google Kubernetes Engine (GKE) application as if they were local file systems. This\nquickstart provides a sample Kubernetes manifest to create a Pod that mounts the\nbucket, and shows you how to interact with the bucket's contents using the Pod's file\nsystem.\n\nThis page is for Developers, Storage specialists, and anyone else\nwho wants to provision and manage cloud resources, and deploy workloads. To\nlearn more about common roles, see\n[Common GKE user roles and tasks](/kubernetes-engine/enterprise/docs/concepts/roles-tasks).\n\nBefore reading this page, ensure that you're familiar with [Kubernetes](https://kubernetes.io/)\nand [Cloud Storage FUSE CSI driver](/kubernetes-engine/docs/concepts/cloud-storage-fuse-csi-driver).\n\nThis quickstart uses the GKE Autopilot mode. If you want to use the\nStandard mode, see [Set up the Cloud Storage FUSE CSI driver for GKE](/kubernetes-engine/docs/how-to/cloud-storage-fuse-csi-driver-setup#standard).\n\nBefore you begin\n\nSign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n\nIn the Google Cloud console, on the project selector page,\nselect or create a Google Cloud project.\n| **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n[Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n\n\n[Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n\n[Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com,storage.googleapis.com) \nIn the Google Cloud console, on the project selector page,\nselect or create a Google Cloud project.\n| **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n[Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n\n\n[Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n\n[Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com,storage.googleapis.com)\n1. Make sure that you have the following role or roles on the project: Kubernetes Engine Admin, Storage Admin, Service Account User\n\nCheck for the roles\n\n1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n2. Select the project.\n3.\n In the **Principal** column, find all rows that identify you or a group that\n you're included in. To learn which groups you're included in, contact your\n administrator.\n\n4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.\n\nGrant the roles\n\n1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n2. Select the project.\n3. Click person_add **Grant access**.\n4.\n In the **New principals** field, enter your user identifier.\n\n This is typically the email address for a Google Account.\n\n5. In the **Select a role** list, select a role.\n6. To grant additional roles, click add **Add\n another role** and add each additional role.\n7. Click **Save**.\n\nCreate a GKE Autopilot cluster\n\n1.\n\n\n In the Google Cloud console, go to the **Create an Autopilot cluster** page.\n\n [Go to Create an Autopilot cluster](https://console.cloud.google.com/kubernetes/auto/add)\n\n \u003cbr /\u003e\n\n2. Under **Cluster basics**, do the following:\n\n 1. In the **Name** field, enter a name for the cluster.\n\n 2. Keep the default values for the rest of the settings.\n\n3. To create the cluster, click **Create**.\n\nCreate a Cloud Storage bucket\n\n1. In the Google Cloud console, go to the Cloud Storage **Buckets** page. \n\n [Go to Buckets](https://console.cloud.google.com/storage/browser)\n2. Click add_box **Create**.\n\n3. On the **Create a bucket** page, in the **Get started** section, do the following:\n\n 1. Enter a globally unique name for your bucket that meets the\n [bucket naming requirements](/storage/docs/buckets#naming).\n\n 2. Keep the default values for the rest of the settings.\n\n4. To create the bucket, click **Create**.\n\nUpload objects to your Cloud Storage bucket\n\n1. In the Google Cloud console, go to the Cloud Storage **Buckets** page. \n\n [Go to Buckets](https://console.cloud.google.com/storage/browser)\n2. In the list of buckets, click the name of the bucket that you just created.\n\n3. In the **Objects** tab for the bucket, do either of the following:\n\n - Drag files from your desktop or file manager\n to the main pane in the Google Cloud console.\n\n - Click the **Upload Files** button. In the dialog that appears, select the\n files that you want to upload, and click **Open**.\n\n | **Note:** If you're using the Chrome browser, folder uploads are also supported.\n\nConfigure access to your Cloud Storage bucket\n\nTo make sure your Cloud Storage bucket is accessible by your GKE\ncluster, follow the steps in [Configure access to Cloud Storage buckets](/kubernetes-engine/docs/how-to/cloud-storage-fuse-csi-driver-setup#authentication).\n\nSet up Cloud Shell\n\nIn the Google Cloud console, activate Cloud Shell.\n\n[Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n\nA [Cloud Shell](/shell/docs/how-cloud-shell-works) session starts and displays a command-line prompt. It can take a few seconds for the session to initialize.\n\nDeploy a Pod to access your Cloud Storage bucket by using FUSE **Note:** To optimize your configuration, see [Optimize Cloud Storage Cloud Storage FUSE CSI driver for GKE performance](/kubernetes-engine/docs/how-to/cloud-storage-fuse-csi-driver-perf).\n\n1. Set the default project where you want\n to deploy the Pod:\n\n gcloud config set project \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your project ID.\n2. Create and apply the Pod manifest with the following content:\n\n cat \u003c\u003c EOF | kubectl apply -f -\n apiVersion: v1\n kind: Pod\n metadata:\n name: gcsfuse-test\n namespace: default\n annotations:\n gke-gcsfuse/volumes: \"true\"\n spec:\n terminationGracePeriodSeconds: 60\n containers:\n - image: busybox\n name: busybox\n command: [\"sleep\"]\n args: [\"infinity\"]\n volumeMounts:\n - name: gcsfuse-test\n mountPath: /data\n readOnly: true\n serviceAccountName: default\n volumes:\n - name: gcsfuse-test\n csi:\n driver: gcsfuse.csi.storage.gke.io\n volumeAttributes:\n bucketName: \u003cvar translate=\"no\"\u003eBUCKET_NAME\u003c/var\u003e\n mountOptions: \"implicit-dirs\"\n EOF\n\n - Replace \u003cvar translate=\"no\"\u003eBUCKET_NAME\u003c/var\u003e with your Cloud Storage bucket name.\n - If you're using a different namespace or a service account, replace the `namespace` and `serviceAccountName` fields accordingly.\n\n The content of this manifest starts a Pod called `gcsfuse-test` that mounts the bucket on its `/data` path.\n3. Verify that the Pod is running:\n\n kubectl get pod gcsfuse-test\n\n The output is similar to the following: \n\n NAME READY STATUS RESTARTS AGE\n gcsfuse-test 2/2 Running 0 12s\n\n The Cloud Storage FUSE CSI driver [attaches a sidecar container](https://kubernetes.io/blog/2023/08/25/native-sidecar-containers/) in your Pod to manage interactions with Cloud Storage.\n\n If the Pod isn't running, you can fetch the event logs to help you diagnose the\n issue by running the `kubectl describe pod gcsfuse-test` command. For more information,\n see [Troubleshooting](https://github.com/GoogleCloudPlatform/gcs-fuse-csi-driver/blob/main/docs/troubleshooting.md#pod-event-warnings) on GitHub.\n4. After the Pod is running, you can explore its file system:\n\n kubectl exec -it gcsfuse-test -- find /data\n\n | **Success:** You've successfully accessed your Cloud Storage bucket as a local file system!\n\nClean up\n\n\u003cbr /\u003e\n\nTo avoid incurring charges to your Google Cloud account for the resources that you used\nin this tutorial, delete the Pod: \n\n kubectl delete pod gcsfuse-test\n\nWhat's next\n\n- [Learn how the Cloud Storage FUSE CSI driver for GKE works](/kubernetes-engine/docs/concepts/cloud-storage-fuse-csi-driver).\n- [Learn more about the capabilities of Cloud Storage FUSE](/storage/docs/cloud-storage-fuse/overview).\n- [Troubleshoot Cloud Storage FUSE](https://github.com/GoogleCloudPlatform/gcs-fuse-csi-driver/blob/main/docs/troubleshooting.md).\n- [Optimize Cloud Storage FUSE for performance](/kubernetes-engine/docs/how-to/cloud-storage-fuse-csi-driver-perf)."]]