Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Como se conectar a buckets do Cloud Storage
Nesta página, apresentamos o Cloud Storage como uma opção para armazenar
dados de machine learning e resultado do treinamento. Também descrevemos como conceder ao
Cloud TPU acesso aos objetos de dados no Cloud Storage.
Antes de começar
É preciso ter uma conta de serviço do Cloud TPU
para acessar um bucket do Cloud Storage.
Crie uma conta de serviço do Cloud TPU para seu projeto.
region é a região em que você criou o Cloud TPU.
Para mais informações sobre regiões e disponibilidade de TPU, consulte
Regiões e zonas de TPU.
bucket-name é o nome do bucket que você quer criar.
Use o comando gcloud storage cp para gravar arquivos no bucket do Cloud Storage:
gcloudstoragecp-rlocal-data-dirgs://bucket-name
em que local-data-dir é um caminho local para seus dados.
Por exemplo:$HOME/your-data
Conceda ao Cloud TPU acesso ao Cloud Storage
É necessário conceder ao Cloud TPU acesso de leitura e gravação aos
objetos do Cloud Storage. Para isso, conceda o acesso necessário à conta de serviço do Cloud TPU usada por ele.
As seções a seguir mostram como encontrar a conta de serviço do Cloud TPU e
conceder o acesso necessário.
Como usar Access Control Lists (ACLs) refinadas para o Cloud TPU (recomendado)
Se você armazenar dados de treinamento no Cloud Storage, será necessário conceder à conta de serviço do Cloud TPU
permissão de leitura e gravação no bucket.
Console
Acesse a página do navegador do Cloud Storage para ver seus buckets.
Selecione Conceder acesso para adicionar uma nova permissão e digite o nome completo da conta de serviço
na caixa de edição Novos principais.
Se você estiver lendo esse bucket, autorize a conta de serviço
da TPU a ler esse recurso. Isso pode ser feito concedendo o
papel Storage Legacy > Storage Legacy Bucket Reader à conta de serviço.
Se você estiver gravando nesse bucket, autorize a conta de serviço
da TPU a gravar nesse recurso. Isso pode ser feito concedendo o
papel Storage Legacy > Storage Legacy Bucket Writer à conta de serviço.
CLI
Se você estiver lendo esse bucket, conceda a permissão de leitura à
conta de serviço do Cloud TPU:
Como usar permissões do IAM para o Cloud TPU (alternativa)
Se você quiser conceder permissões mais amplas, em vez de conceder acesso a cada bucket explicitamente, conceda à conta de serviço do Cloud TPU o papel de Administrador do Storage no Identity Access Management (IAM).
Clique no botão Conceder acesso para adicionar participantes ao projeto.
Insira os nomes da conta de serviço do Cloud TPU na caixa de texto Principais.
Clique na lista suspensa Papéis.
Ative os seguintes papéis:
Projeto > Leitor
Storage > Administrador do Storage
Cloud Storage FUSE
O Cloud Storage FUSE permite
montar e acessar buckets do Cloud Storage como sistemas de arquivos locais. Isso permite
que os aplicativos leiam e gravem objetos no bucket usando a semântica padrão
de sistemas de arquivos.
Consulte a documentação do Cloud Storage FUSE
para saber como ele funciona e como as operações do Cloud Storage FUSE são mapeadas. Confira
mais informações sobre como usar o Cloud Storage FUSE, como instalar a
CLI gcsfuse e montar buckets no
GitHub.
Limpar
Desconecte-se do Cloud TPU, se ainda não tiver feito isso:
(vm)$exit
No Cloud Shell, exclua a Cloud TPU:
gcloudcomputetpustpu-vmdeletetpu-name--zone=zone
Execute gcloud compute tpus tpu-vm list para verificar se a VM foi excluída. A
exclusão pode levar vários minutos.
gcloudcomputetpustpu-vmlist--zone=zone
Uma resposta como esta indica que suas instâncias foram
excluídas.
Listed0items
Execute o comando a seguir para excluir o bucket do Cloud Storage e o
conteúdo dele, substituindo bucket-name pelo nome do bucket que você
criou:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-18 UTC."],[],[],null,["# Connecting to Cloud Storage Buckets\n===================================\n\nThis page introduces [Cloud Storage](/storage/docs) as an option for storing your\nmachine learning data and training output, and describes how to give your\nCloud TPU access to the data objects on Cloud Storage.\n\nBefore you begin\n----------------\n\nYou need a Cloud TPU [service account](/iam/docs/service-accounts)\nin order to access a Cloud Storage\nbucket.\n| **Note:** Once you set up a service account for your project, it stays set while the project is active; you don't have to set up the service account every time you run a training workload in the same project.\n\n1. Create a Cloud TPU service account for your project.\n\n ```bash\n gcloud beta services identity create --service tpu.googleapis.com --project project-id\n ```\n\n The command returns a Cloud TPU service account with following format: \n\n ```\n service-project-number@cloud-tpu.iam.gserviceaccount.com\n ```\n | **Important:** This command creates a [service agent](/iam/docs/service-agents), a special type of Google-managed service account which is not listed in your Service accounts page in the Google Cloud console.\n2. Follow the instructions found in either the\n [Cloud TPU quickstart guides](/tpu/docs/quickstart) or\n [Manage TPUs](/tpu/docs/managing-tpus-tpu-vm)\n to configure your Google Cloud project and create your Cloud TPU\n VM and TPU resources.\n\nWrite data to Cloud Storage\n---------------------------\n\n**Note:** Set up the Cloud Storage bucket in the same location (region) that you set up the Cloud TPU. See [Create buckets](/storage/docs/creating-buckets) for all options available for managing storage buckets. \n\n### Console\n\n1. Go to the Cloud Storage page on the Google Cloud console.\n\n [Go to the Cloud Storage page](https://console.cloud.google.com/storage/browser)\n2. Create a new bucket, specifying the following options:\n\n - A unique name of your choosing.\n - Default storage class: `Standard`\n - Location: The region where you created the Cloud TPU. For more information about regions and TPU availability, see [TPU regions and zones](/tpu/docs/regions-zones).\n\n### CLI\n\n1. Use the `gcloud storage buckets create` command to create a Cloud Storage bucket:\n\n ```bash\n gcloud storage buckets create gs://bucket-name --location region\n ```\n\n where:\n - \u003cvar translate=\"no\"\u003eregion\u003c/var\u003e is the region where you created the Cloud TPU.\n For more information about regions and TPU availability, see\n [TPU regions and zones](/tpu/docs/regions-zones).\n\n - \u003cvar translate=\"no\"\u003ebucket-name\u003c/var\u003e is the name of the bucket you want to create.\n\n2. Use the `gcloud storage cp` command to write files to the Cloud Storage bucket:\n\n ```bash\n gcloud storage cp -r local-data-dir gs://bucket-name\n ```\n\n where \u003cvar translate=\"no\"\u003elocal-data-dir\u003c/var\u003e is a local path to your data.\n For example:`$HOME/your-data`\n\nGive your Cloud TPU access to Cloud Storage\n-------------------------------------------\n\nYou need to give your Cloud TPU read and write access to your\nCloud Storage objects. To do that, you must grant the required access to\nthe Cloud TPU service account used by the Cloud TPU.\nThe following sections show how to find the Cloud TPU service account and\ngrant the necessary access.\n\n### Authorize the Cloud TPU service account\n\nThe recommended way to authorize the Cloud TPU service account is by using\n[fine-grained access control lists (ACLs)](#fine-grained-acl). You can also grant\nbroader permissions using [IAM permissions](#iam-permissions).\n\n#### Using fine-grained ACLs for Cloud TPU (Recommended)\n\nIf you store training data on Cloud Storage, the Cloud TPU\nservice account needs read and write permission on the bucket. \n\n### Console\n\n1. Go to the Cloud Storage browser page to view the buckets you own.\n\n [Go to the Cloud Storage browser](https://console.cloud.google.com/storage/browser)\n\n \u003cbr /\u003e\n\n2. Select the bucket whose ACL you want to modify.\n\n3. Select the **Permissions** tab.\n\n4. Select **Grant access** to add a new permission and type the complete service account\n name in the **New principals** edit box.\n\n5. If you are *reading* from this bucket, you must authorize the TPU Service\n Account to read from the resource. Do this by granting the Service\n Account the `Storage Legacy \u003e Storage Legacy Bucket Reader` role.\n\n6. If you are *writing* to this bucket, you must authorize the TPU Service\n Account to write to the resource. Do this by granting the Service\n Account the `Storage Legacy \u003e Storage Legacy Bucket Writer` role.\n\n### CLI\n\n1. If you are *reading* from this bucket, grant read permission for\n the Cloud TPU service account:\n\n \u003cbr /\u003e\n\n ```bash\n gcloud storage buckets add-iam-policy-binding gs://bucket-name --member=serviceAccount:service-account --role=roles/storage.objectViewer\n \n ```\n\n \u003cbr /\u003e\n\n2. If you are *writing* to this bucket, grant write permission for\n the Cloud TPU service account:\n\n \u003cbr /\u003e\n\n ```bash\n gcloud storage buckets add-iam-policy-binding gs://bucket-name --member=serviceAccount:service-account --role=roles/storage.objectCreator\n ```\n\n \u003cbr /\u003e\n\n#### Using IAM permissions for Cloud TPU (Alternative)\n\nIf you want to grant broader permissions instead of granting access to each\nbucket explicitly, you can grant the Identity Access Management (IAM) Storage\nAdmin role to the Cloud TPU service account.\n\n1. [Go to IAM](https://console.cloud.google.com/iam-admin/iam)\n\n2. Click the **Grant access** button to add principals to the project.\n\n3. Enter the names of the Cloud TPU service account in the\n **Principals** text box.\n\n4. Click the **Roles** dropdown list.\n\n5. Enable the following roles:\n\n - **Project \\\u003e Viewer**\n\n - **Storage \\\u003e Storage Admin**\n\n### Cloud Storage FUSE\n\nCloud Storage FUSE allows you to\nmount and access Cloud Storage buckets as local file systems. This allows\napplications to read and write objects in your bucket using standard\nfile system semantics.\n\nSee the [Cloud Storage FUSE documentation](/storage/docs/gcs-fuse)\nfor details about how Cloud Storage FUSE works and a description of how\nCloud Storage FUSE operations map to Cloud Storage operations. You can find\nadditional information about how to use Cloud Storage FUSE, such as how to\ninstall the gcsfuse CLI and mounting buckets on\n[GitHub.](https://github.com/GoogleCloudPlatform/gcsfuse/tree/master/docs)\n\nClean up\n--------\n\n1. Disconnect from the Cloud TPU, if you have not already done so:\n\n ```bash\n (vm)$ exit\n ```\n2. In your Cloud Shell, delete the Cloud TPU:\n\n ```bash\n gcloud compute tpus tpu-vm delete tpu-name --zone=zone\n ```\n3. Verify the VM has been deleted by running `gcloud compute tpus tpu-vm list`. The\n deletion might take several minutes.\n\n ```bash\n gcloud compute tpus tpu-vm list --zone=zone\n ```\n\n A response like the following indicates your instances have been\n successfully deleted. \n\n Listed 0 items\n\n4. Run the following command to delete the Cloud Storage bucket and its\n contents, replacing \u003cvar translate=\"no\"\u003ebucket-name\u003c/var\u003e with the name of the bucket you\n created:\n\n ```bash\n gcloud storage rm --recursive gs://bucket-name\n ```\n\nWhat's next\n-----------\n\n- For more information about creating Cloud Storage buckets and writing data to those buckets, see the [Cloud Storage create buckets\n documentation](/storage/docs/creating-buckets).\n- For more information about service accounts, see the [authentication overview](/docs/authentication)."]]