[[["易于理解","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):2024-11-26。"],[],[],null,["# Access scopes in GKE\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nThis page describes the default access scopes granted to nodes in\nGoogle Kubernetes Engine (GKE) clusters. By reading this page, you learn about\nthe default access scopes that are granted to clusters, and how you can configure\ncustom access scopes, if required.\n\nThis page is for Security specialists and Operators who\ncreate and manage clusters, and must understand the default access that is granted\nto clusters and how to modify that access if needed.\nTo learn more about\ncommon roles and example tasks that we reference in Google Cloud content, see\n[Common GKE user roles and tasks](/kubernetes-engine/enterprise/docs/concepts/roles-tasks).\n\nWhat are access scopes?\n-----------------------\n\nAccess scopes are the legacy method of granting permissions for your nodes, and\nfor workloads running on your nodes if the workloads use\n[application default credentials (ADC)](/docs/authentication/application-default-credentials).\nAccess scopes define the OAuth scopes used in API calls from client libraries or the\ngcloud CLI.\n\nWe recommend that you don't specify your own access scopes. Instead, you should\nuse\n[IAM permissions](/iam/docs/creating-managing-service-accounts#creating)\nor\n[Kubernetes role-based access control (RBAC)](/kubernetes-engine/docs/how-to/role-based-access-control)\nto grant access to specific IAM service accounts or Kubernetes\nservice accounts.\n\nDefault access scopes\n---------------------\n\nWhen you create a new GKE cluster, Google Cloud assigns a\ndefault set of access scopes to nodes based on the service account used by the\nnodes. These access scopes enable specific functionality for GKE.\nYou can also set access scopes manually using the `--scopes` flag when you\ncreate\n[Standard clusters](/sdk/gcloud/reference/container/clusters/create#--scopes),\n[Autopilot clusters](/sdk/gcloud/reference/container/clusters/create-auto#--scopes),\nor [node pools](/sdk/gcloud/reference/container/node-pools/create#--scopes). You\ncan't modify the access scopes on existing node pools. Instead, create a new\nnode pool with the new scopes and migrate workloads to that node pool.\n\nThe following sections describe the default access scopes that GKE\nadds to nodes based on whether you specify a custom service account, and whether\nyou manually specify access scopes.\n\n### Autopilot clusters\n\n### Standard clusters\n\nConfigure a custom service account for workloads\n------------------------------------------------\n\n[IAM](/iam/docs/overview) is the access control\nsystem for granting authorized roles to users and service accounts within your\nGoogle Cloud project. A [service account](/iam/docs/service-accounts) is a\nspecial Google Account that performs tasks, such as deploying applications, on\nyour behalf.\nYou use IAM to create a service account, then use\nIAM policy bindings to secure the account.\n\nIf your workloads require access to Compute Engine, grant the service\naccount\nthe [Compute Engine Admin](/compute/docs/access/iam#compute.admin) role.\nIf your workloads need to pull private images from Artifact Registry, see\n[Configuring access control for Artifact Registry repositories](/artifact-registry/docs/access-control).\n\n### Create a service account\n\nTo create a custom service account named `kubernetes-engine-node-sa`, run the\nfollowing commands: \n\n export NODE_SA_NAME=kubernetes-engine-node-sa\n gcloud iam service-accounts create $NODE_SA_NAME \\\n --display-name \"GKE Node Service Account\"\n export NODE_SA_EMAIL=`gcloud iam service-accounts list --format='value(email)' \\\n --filter='displayName:GKE Node Service Account'`\n\n| **Note:** These commands export two variables, `$NODE_SA_NAME` and `$NODE_SA_EMAIL`, that are used in commands documented later on this page.\n\n### Grant minimal roles\n\nTo configure the service account with the *minimal* necessary roles and\npermissions for your GKE node to function, run the following\ncommands, where `$PROJECT` is your\n[project ID](https://support.google.com/cloud/answer/6158840): \n\n export PROJECT=`gcloud config get-value project`\n gcloud projects add-iam-policy-binding $PROJECT \\\n --member serviceAccount:$NODE_SA_EMAIL \\\n --role roles/monitoring.metricWriter\n gcloud projects add-iam-policy-binding $PROJECT \\\n --member serviceAccount:$NODE_SA_EMAIL \\\n --role roles/monitoring.viewer\n gcloud projects add-iam-policy-binding $PROJECT \\\n --member serviceAccount:$NODE_SA_EMAIL \\\n --role roles/logging.logWriter\n\n### Grant additional roles\n\n| **Caution:** The `compute.admin` role shouldn't be granted to this service account unless necessary. Granting this role allows workloads to create, delete, read metadata on, and access nodes using SSH, among other operations.\n\nTo grant the service account the [Compute Engine Admin](/compute/docs/access/iam#compute.admin)\nrole, run the following command: \n\n gcloud projects add-iam-policy-binding $PROJECT \\\n --member serviceAccount:$NODE_SA_EMAIL \\\n --role roles/compute.admin\n\nTo learn how to grant service accounts access to private images stored in\nArtifact Registry, see [Granting access to Google Kubernetes Engine clusters](/artifact-registry/docs/access-control#gke).\n\n### Create a cluster or node pool with the custom service account\n\nTo create a cluster that uses the custom service account, run the following\ncommand: \n\n gcloud container clusters create --service-account=$NODE_SA_EMAIL\n\nTo create a node pool in an existing cluster: \n\n gcloud container node-pools create --service-account=$NODE_SA_EMAIL\n\n| **Note:** You can also find the service account's email address by running the following command: \n|\n| ```\n| gcloud iam service-accounts list --format='value(email)' \\\n| --filter='displayName:Node Service Account'\n| ```"]]