[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-31 (世界標準時間)。"],[],[],null,["# Load balancer subnets\n\nThis page describes how GKE on AWS works with AWS to\nchoose subnets for Service load balancers, and how to tag subnets to be\nauto-discovered during Service load balancer creation.\n\nWhy you need to specify subnets\n-------------------------------\n\nWhen creating load balancers, AWS needs to know which subnets to\nplace them in. The subnet determines load balancer availability zones, IP\naddresses, and endpoints.\n\nNormally, load balancers are allocated to one subnet for each availability zone\ncontaining a node pool. AWS needs a minimum of one available subnet to create a\nNetwork Load Balancer (NLB), and a minimum of two subnets for an Application\nLoad Balancer (ALB).\n\nAll AWS subnets are either public (with public IPs and a route to the VPC's\ninternet gateway) or private (lacking these features). Internet-facing load\nbalancers must be located in public subnets. Internal load balancers can\nreside in either public or private subnets.\n\n### If there are no tagged subnets available\n\nIf GKE on AWS needs to create a load balancer and no tagged subnets\nare available or have capacity, it might create the load balancer in another\nsubnet. To avoid this and control which subnets your load balancers are placed\nin, you should tag all your subnets.\n\nSubnet auto-discovery\n---------------------\n\nGKE on AWS will auto-discover subnets to use for a load balancer by\nlisting all the subnets in the VPC, and selecting up to one subnet from each\navailability zone.\n\nFor GKE on AWS to auto-discover a subnet, the subnet must:\n\n- Be tagged with `kubernetes.io/role/elb` (for an internet-facing load balancer)\n- Be tagged with `kubernetes.io/role/internal-elb` (for an internal load balancer)\n- Either contain no tags with prefix `kubernetes.io/cluster/`, or contain the tag `kubernetes.io/cluster/`\u003cvar translate=\"no\"\u003eCLUSTER_UID\u003c/var\u003e, where \u003cvar translate=\"no\"\u003eCLUSTER_UID\u003c/var\u003e is the current cluster's UID.\n\nIn addition, a subnet intended for use with an internet-facing load balancer\nmust have a route to the VPC's internet gateway.\n\nIf there are several subnets in an availability zone that satisfy the load\nbalancer's requirements, GKE on AWS ranks subnets in\norder by their subnet ID.\n\nTag your subnets for their intended use\n---------------------------------------\n\nFor GKE on AWS to auto-discover a subnet for a load balancer, you\nmust apply one of two tags to the subnet to signal its availability. They are:\n\n- `kubernetes.io/role/elb`: apply this tag to your subnet to mark it as\n available for an internet-facing load balancer. This must be a public\n subnet with a route to your VPC's internet Gateway. Set the tag to `1`.\n To apply this tag, run the following command:\n\n aws ec2 create-tags \\\n --resources \u003cvar translate=\"no\"\u003eSUBNET_ID\u003c/var\u003e \\\n --tags \"Key=kubernetes.io/role/elb,Value=1\"\n\n- `kubernetes.io/role/internal-elb`: apply this tag to your subnet\n to mark it as available for an internal load balancer. Set the tag's\n value to `1`. To apply this tag, run the following command:\n\n aws ec2 create-tags \\\n --resources \u003cvar translate=\"no\"\u003eSUBNET_ID\u003c/var\u003e \\\n --tags Key=kubernetes.io/role/internal-elb,Value=1\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSUBNET_ID\u003c/var\u003e: the ID of the subnet you're tagging\n\nAfter giving your subnet a `kubernetes.io/role` tag, you can also tag it with\none or more `kubernetes.io/cluster/`\u003cvar translate=\"no\"\u003eCLUSTER_UID\u003c/var\u003e tags,\nwhere \u003cvar translate=\"no\"\u003eCLUSTER_UID\u003c/var\u003e is the UID of a GKE on AWS cluster.\nThis prevents any cluster not listed in one of these tags from auto-discovering\nthe subnet for use by its load balancers.\n\nSee the Amazon\n[aws ec2 create-tags](https://docs.aws.amazon.com/cli/latest/reference/ec2/create-tags.html#create-tags)\ndocumentation for more information about the `aws ec2 create-tags` command.\n\nTroubleshooting\n---------------\n\nThe most common problem with load balancer configuration is incorrectly tagged\nsubnets. This can cause the auto-discovery algorithm to select the wrong\nsubnets. To diagnose and resolve this problem:\n\n- If you're creating an internet-facing load balancer, make sure there is\n at least one public subnet in each of the availability zones that contain a\n node pool, and that the subnets are tagged with `kubernetes.io/role/elb`.\n\n- If you're creating an internal load balancer, make sure there is\n at least one subnet in each of the availability zones that contain a\n node pool, and that the subnets are tagged with\n `kubernetes.io/role/internal-elb`.\n\n- Check whether the subnets you want auto-discovered have any tags of the form\n `kubernetes.io/cluster/`\u003cvar translate=\"no\"\u003eCLUSTER_UID\u003c/var\u003e. If a subnet has any\n such tags naming a cluster, the subnet can only be auto-discovered\n by the named clusters. To resolve this, either delete all cluster name tags\n (to let the subnet be auto-discovered from any cluster) or add a cluster\n name tag with your GKE on AWS cluster UID and a value of `shared`.\n\n- Check the Kubernetes event history with the following command:\n\n kubectl get events -A | grep LoadBalancer\n\n For example, the event message `could not find any suitable subnets for\n creating the ELB` indicates that no subnets could be auto-discovered. If\n you get this warning, ensure that your subnets and their tags are correct and\n complete.\n- To list the subnets that can be auto-discovered for internet-facing load\n balancers, run the following command:\n\n aws ec2 describe-subnets \\\n --filters \"Name=vpc-id,Values=\u003cvar translate=\"no\"\u003eVPC_ID\u003c/var\u003e\" \"Name=tag:kubernetes.io/role/elb,Values=*\"\n\n Replace \u003cvar translate=\"no\"\u003eVPC_ID\u003c/var\u003e with the ID of your VPC.\n- To list the subnets that can be auto-discovered for internal load balancers,\n run:\n\n aws ec2 describe-subnets \\\n --filters \"Name=vpc-id,Values=\u003cvar translate=\"no\"\u003eVPC_ID\u003c/var\u003e\" \"Name=tag:kubernetes.io/role/internal-elb,Values=*\"\n\nNext steps\n----------\n\n- Learn more about [network load balancing](/kubernetes-engine/multi-cloud/docs/aws/how-to/network-load-balancing)\n\n- [Set up an HTTP Load Balancer](/kubernetes-engine/multi-cloud/docs/aws/how-to/http-load-balancing)."]]