GOOGLE_PROJECT_ID:您的 Google 项目 ID。您可以在 Google Cloud 控制台的信息中心页面左侧找到此信息。
ACCOUNT_EMAILS:创建集群后可以登录集群的电子邮件地址列表(以英文逗号分隔),例如 "admin@example.com","operator@example.com"。至少一个地址必须具有 Google Cloud 账号。如需为集群添加其他身份提供方,请参阅使用 GKE Identity Service 管理身份。
[[["易于理解","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-08-08。"],[],[],null,["# Create a VPC and cluster with Terraform\n\nOverview\n--------\n\nTerraform is an open source tool for configuring cloud environments such as\nAWS and installing software such as Kubernetes on\nthem. You can configure your AWS environment and create your clusters\nin it either with Terraform or with the GKE on AWS\n[installation instructions](/kubernetes-engine/multi-cloud/docs/aws/how-to/create-cluster).\n\nThis page describes how to use Terraform to configure your AWS\nenvironment and install a cluster using a sample configuration\nstored on GitHub. This page is for IT administrators and Operators\nwho want to set up, monitor, and manage cloud infrastructure, automate\ndeployments, and use templates and declarative configuration. To learn more\nabout common roles and example tasks that we reference in Google Cloud content,\nsee\n[Common GKE user roles and tasks](/kubernetes-engine/enterprise/docs/concepts/roles-tasks).\n\nTo use these scripts, you need a basic familiarity\nwith Terraform. In particular, you must edit the Terraform configuration files\nto add your own user and project information and to make any changes you need to\nthe default cluster configuration.\n\nTo configure your AWS environment and create clusters without using\nTerraform, see\n[AWS prerequisites overview](/kubernetes-engine/multi-cloud/docs/aws/how-to/prerequisites)\nand the instructions to [create a cluster](/kubernetes-engine/multi-cloud/docs/aws/how-to/create-cluster).\n\n### What the scripts do\n\nThis script configures Terraform to create an AWS VPC and deploy\na cluster on it. The resulting VPC meets all\nGKE on AWS [prerequisites](/kubernetes-engine/multi-cloud/docs/aws/how-to/prerequisites)\nand has the same network topology as the VPC created by Google's manual\n[VPC creation instructions](/kubernetes-engine/multi-cloud/docs/aws/how-to/create-aws-vpc#create-sample-vpc).\n\nThe cluster that the script set creates has the following characteristics:\n\n- three control plane nodes (one in each of the three configured availability zones). These nodes are of type [t3.large](https://aws.amazon.com/ec2/instance-types/t3/).\n- One node pool with two nodes of type [t3.large](https://aws.amazon.com/ec2/instance-types/t3/). This node pool is deployed in the AWS `us-east-1` region and can autoscale to five nodes.\n\n### How to change the default VPC and cluster\n\nYou can change the characteristics of the VPC and cluster created by the Terraform\nscripts by editing the appropriate Terraform files.\n\n- Adjust the region and availability zones by editing the `variables.tf` file.\n- Change the [AWS instance type](/kubernetes-engine/multi-cloud/docs/aws/reference/supported-instance-types).\n- Alter the characteristics of the VPC, including the subnets, availability zones and load balancer, by editing the files in the `modules/vpc` subfolder.\n\nFor a list of AWS regions controlled from a particular Google Cloud\nregion and their associated Kubernetes versions, run the following command: \n\n gcloud container aws get-server-config --location `\u003cvar translate=\"no\"\u003eGOOGLE_CLOUD_REGION\u003c/var\u003e`\n\nReplace \u003cvar translate=\"no\"\u003eGOOGLE_CLOUD_REGION\u003c/var\u003e with the name of the\n[Google Cloud region](/kubernetes-engine/multi-cloud/docs/aws/reference/supported-regions) you want\nGKE on AWS to control your cluster from.\n\nPrerequisites\n-------------\n\n1. Install the Google Cloud CLI with the\n [Google Cloud CLI installation instructions](/sdk/docs/install).\n If you've already installed it, use these instructions to make sure you're running\n version 412.0.0 or higher.\n\n2. Install the AWS CLI with the\n [AWS CLI installation instructions](/kubernetes-engine/multi-cloud/docs/aws/how-to/configure-aws-cli).\n\n3. Create your\n [AWS access keys](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-prereqs.html#getting-started-prereqs-keys).\n\n4. Configure your local AWS environment with the following command:\n\n aws configure\n\nPrepare Terraform\n-----------------\n\n1. Configure Google Cloud CLI authentication by running the following commands:\n\n gcloud config set project \u003cvar translate=\"no\"\u003eGOOGLE_PROJECT_ID\u003c/var\u003e\n gcloud auth application-default login --no-launch-browser\n\n2. Enable the required services in your Google Cloud project.\n\n gcloud --project=\"\u003cvar translate=\"no\"\u003eGOOGLE_PROJECT_ID\u003c/var\u003e\" services enable \\\n gkemulticloud.googleapis.com \\\n gkeconnect.googleapis.com \\\n connectgateway.googleapis.com \\\n cloudresourcemanager.googleapis.com \\\n anthos.googleapis.com \\\n logging.googleapis.com \\\n monitoring.googleapis.com \\\n opsconfigmonitoring.googleapis.com\n\n Replace \u003cvar translate=\"no\"\u003eGOOGLE_PROJECT_ID\u003c/var\u003e with your Google project ID.\n3. Make a local copy of the repository and change to the `AWS` folder:\n\n git clone https://github.com/GoogleCloudPlatform/anthos-samples.git\n cd anthos-samples/anthos-multi-cloud/AWS\n\nDeploy GKE on AWS\n-----------------\n\n1. Edit the following lines in the `terraform.tfvars` file to replace the\n default values:\n\n gcp_project_id = \u003cvar translate=\"no\"\u003eGOOGLE_PROJECT_ID\u003c/var\u003e\n admin_users = [\"\u003cvar translate=\"no\"\u003eGCP_ACCOUNT_EMAIL\u003c/var\u003e\"]\n cluster_version = \u003cvar translate=\"no\"\u003eGKE_VERSION\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eGOOGLE_PROJECT_ID\u003c/var\u003e: your Google project id. You can find\n this on the left side of the dashboard page of the\n [Google Cloud console](https://console.cloud.google.com/home).\n\n - \u003cvar translate=\"no\"\u003eACCOUNT_EMAILS\u003c/var\u003e: a comma-separated list of email\n addresses that can login to the clusters after it's created--- for\n example `\"admin@example.com\",\"operator@example.com\"`. At least one address\n must have a Google Cloud account. To add additional identity\n providers to your cluster, see\n [Manage identity with GKE Identity Service](/kubernetes-engine/multi-cloud/docs/aws/how-to/anthos-identity-service).\n\n - \u003cvar translate=\"no\"\u003eGKE_VERSION\u003c/var\u003e: a supported GKE version for your chosen\n region. To find the supported versions, see\n [GKE on AWS versioning and support](/kubernetes-engine/multi-cloud/docs/aws/reference/version-lifespans#version_lifespans).\n\n2. Initialize and create the Terraform plan:\n\n terraform init\n\n Terraform installs any needed libraries, such as the Google Cloud\n provider.\n3. Apply the Terraform plan to create the AWS Virtual Private Cloud and cluster:\n\n terraform apply\n\n Follow the instructions to start creating a cluster.\n\nThe installation takes about 12 minutes. When Terraform completes creating your\nAWS Virtual Private Cloud and cluster, it prints out information on the cluster and creates a\nfile named `var.sh`. You can use the values in this file if you create\nadditional node pools.\n\nTo verify that the cluster has been created successfully, watch for it to\nappear in the\n[Kubernetes Engine page](https://console.cloud.google.com/kubernetes/list/overview)\nof the Google Cloud console in your Google Cloud project.\n\nConnect to your cluster\n-----------------------\n\nTo verify connectivity to your cluster and fetch its details, run the following\ncommand: \n\n gcloud container fleet memberships get-credentials \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e\n kubectl get nodes\n\nReplace \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e with the name of your cluster. You can\nfind your cluster name in the `var.sh` Terraform output file.\n\nThe output includes a list of nodes in your cluster and their status.\n\nDelete your cluster and AWS Virtual Private Cloud\n-------------------------------------------------\n\nBefore you delete your cluster and AWS Virtual Private Cloud, you must remove all of the\nfollowing:\n\n- Any active AWS load balancers in the AWS Virtual Private Cloud\n- Any additional node pools in your cluster not created with Terraform\n- Any additional clusters in the AWS Virtual Private Cloud not created with Terraform\n\nTo remove the cluster and AWS Virtual Private Cloud you created with Terraform, run the\nfollowing command: \n\n terraform destroy\n\nTerraform drains workloads from your nodes, deletes your primary node pool and\ncluster, and deletes your AWS Virtual Private Cloud.\n\nAuthorize Cloud Logging and Cloud Monitoring\n--------------------------------------------\n\n| **Note:** Starting with GKE on AWS version 1.28, manual policy binding to authorize the `gke-system/gke-telemetry-agent` service account for log and metric collection is no longer necessary. The required permissions are now automatically granted to this service account. You can therefore disregard this section.\n\nIf you want to enable Cloud Logging and Cloud Monitoring, you must add an\n[allow policy](/iam/docs/policies) to your Google Cloud project after you create a\ncluster.\n\nAdd an allow policy with the Google Cloud CLI: \n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=\"serviceAccount:\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.svc.id.goog[gke-system/gke-telemetry-agent]\" \\\n --role=roles/gkemulticloud.telemetryWriter\n\nReplace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your project ID.\n\nNext steps\n----------\n\n- To learn about Google's centralized cluster event logging, see [Cloud Logging](/kubernetes-engine/multi-cloud/docs/aws/how-to/cloud-logging).\n- To read about Google's Cloud Monitoring tools, see [Cloud Monitoring](/kubernetes-engine/multi-cloud/docs/aws/how-to/cloud-monitoring).\n- To install centralized configuration management, see [Configure a cluster with Config Controller](/anthos-config-management/docs/tutorials/manage-resources-config-controller).\n\nFor more information about Terraform GKE on AWS scripts, see\n\n- [Terraform AWS clusters reference](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_aws_cluster)\n- [Terraform AWS node pool reference](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_aws_node_pool)"]]