[[["易于理解","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-03。"],[],[],null,["# Preparing AWS networking\n\nTo set up an externally facing load balancer with GKE on AWS,\nyou need to tag your VPC and public subnet with your cluster ID. If you\nhave already tagged your VPC and subnet, skip to\n[Enabling Ingress](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/ingress).\n\nBefore you begin\n----------------\n\n\nBefore you start using GKE on AWS, make sure you have performed the following tasks:\n\n- Complete the [Prerequisites](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/prerequisites).\n\n\u003c!-- --\u003e\n\n- Install a [management service](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/installing-management).\n- Create a [user cluster](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/creating-user-cluster).\n\nGKE on AWS requires tags on subnets that contain load balancer\nendpoints. GKE on AWS automatically tags all subnets specified in the\n[`spec.Networking.ServiceLoadBalancerSubnetIDs`](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/reference/awscluster#specnetworking)\nfield of the `AWSCluster` resource.\n\nIf you would like to add additional subnets to your user cluster, or if you need\nto re-apply tags to existing subnets, perform the following steps.\n\n1. From your `anthos-aws` directory, use\n `anthos-gke` to switch context to your management service.\n\n ```sh\n cd anthos-aws\n anthos-gke aws management get-credentials\n ```\n | **Note:** `anthos-gke` uses the credentials you specified when you ran `aws configure`.\n\n \u003cbr /\u003e\n\n2. Get the ID of your cluster's AWS VPC with `kubectl` and store it as a\n variable.\n\n export VPC_ID=$(\\\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl get awscluster cluster-0 -o jsonpath='{.spec.networking.vpcID}')\n\n3. Check the variables content with `echo`. The output\n resembles `vpc-12345678abcdef0`.\n\n echo $VPC_ID\n\n4. Save your cluster ID into an environment variable.\n\n export CLUSTER_ID=$(\\\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl get awscluster cluster-0 -o jsonpath='{.status.clusterID}')\n\n You can check the variable with `echo`: \n\n echo $CLUSTER_ID\n\n The response includes your cluster ID. \n\n gke-12345678\n\n5. If you installed GKE on AWS into a dedicated VPC, you can use\n the `aws` command-line tool to retrieve the subnet ID.\n\n Select from the following options:\n - Public, if you want to expose Services on your public subnet.\n - Private, if you want to expose Services on your private subnet.\n - Multiple subnets, if you want to expose Services on multiple subnets.\n\n ### Public\n\n export SUBNET_ID=$(aws ec2 describe-subnets \\\n --filters \"Name=vpc-id,Values=$VPC_ID\" \"Name=tag:Name,Values=*public*\" \\\n --query \"Subnets[*].SubnetId\" \\\n --output text)\n\n The output is an object that contains your subnet ID. It resembles\n `subnet-1234abcdefg`. You can check the variable with `echo`: \n\n echo $SUBNET_ID\n\n The response includes your subnet ID. \n\n subnet-012345678abcdef\n\n ### Private\n\n export SUBNET_ID=$(aws ec2 describe-subnets \\\n --filters \"Name=vpc-id,Values=$VPC_ID\" \"Name=tag:Name,Values=*private*\" \\\n --query \"Subnets[*].SubnetId\" \\\n --output text)\n\n The output is an object that contains your subnet ID. It resembles\n `subnet-1234abcdefg`. You can check the variable with `echo`: \n\n echo $SUBNET_ID\n\n The response includes your subnet ID. \n\n subnet-012345678abcdef\n\n ### Multiple subnets\n\n If you are using multiple subnets for your AWSNodePools\n (for example, if you use multiple availability zones), you need to\n tag your subnet IDs individually.\n | **Note:** The following commands assume your subnets have `public` or `private` in their name. If your subnets do not include this text, change the parameters of the `--filters` flag. See [Using filtering](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Filtering.html) for more information.\n\n Retrieve your list of subnet IDs with `aws ec2 describe-subnets`.\n\n To get a list of all public subnets, run the following command: \n\n aws ec2 describe-subnets \\\n --filters \"Name=vpc-id,Values=$VPC_ID\" \"Name=tag:Name,Values=*public*\" \\\n --query \"Subnets[*].SubnetId\" \\\n --output text\n\n To get a list of all private subnets, run the following command: \n\n aws ec2 describe-subnets \\\n --filters \"Name=vpc-id,Values=$VPC_ID\" \"Name=tag:Name,Values=*private*\" \\\n --query \"Subnets[*].SubnetId\" \\\n --output text\n\n The response includes your subnet IDs. \n\n subnet-012345678abcdef\n subnet-abcdef123456789\n subnet-123456789abcdef\n\n6. Tag your subnet with your cluster ID. If you have multiple subnets,\n select Multiple subnets.\n\n ### Single subnet\n\n aws ec2 create-tags \\\n --resources $SUBNET_ID \\\n --tags Key=kubernetes.io/cluster/$CLUSTER_ID,Value=shared\n\n ### Multiple subnets\n\n For each of your subnets, run the following command: \n\n aws ec2 create-tags \\\n --resources \u003cvar translate=\"no\"\u003esubnet-ids\u003c/var\u003e \\\n --tags Key=kubernetes.io/cluster/$CLUSTER_ID,Value=shared\n\n Replace \u003cvar translate=\"no\"\u003esubnet-ids\u003c/var\u003e with the list of subnet IDs, separated by\n spaces. For example,\n `subnet-012345678abcdef subnet-abcdef123456789 subnet-123456789abcdef`."]]