The product described by this documentation, Anthos Clusters on AWS (previous generation), is now in maintenance mode. All new installs must use the current generation product, Anthos clusters on AWS.
From your anthos-aws directory, use
anthos-gke to switch context to your user cluster.
cd anthos-aws
env HTTPS_PROXY=http://localhost:8118 \
anthos-gke aws clusters get-credentials CLUSTER_NAME
Replace CLUSTER_NAME with your user cluster name.
Have the curl command line tool or a similar tool installed.
Selecting an external or internal load balancer
GKE on AWS creates an external (in your public subnet) or
internal (in your private subnet) load balancer depending on
an annotation to the LoadBalancer resource.
Choose if you want to create a Classic Load Balancer (Classic ELB) or a
Network Load Balancer (NLB). For more information on the differences between
load balancer types, see
Load balancer types
in the AWS documentation.
Creating a LoadBalancer
You create a load balancer by creating a deployment and exposing that deployment
with a service.
Create your deployment. Containers in this Deployment listen on port 50001.
Save the following YAML to a file named my-deployment-50001.yaml:
Create a Service of type LoadBalancer for your deployment. You can create
a Classic or Network ELB on either your public or private subnet.
Choose from one of the following options:
A Classic ELB on the public subnet
An NLB on the public subnet
A Classic ELB on the private subnet
An NLB on the private subnet
Then, copy the following manifest to a file named my-lb-service.yaml.
You create a private LoadBalancer by setting the annotation
service.beta.kubernetes.io/aws-load-balancer-internal
to "true". The following YAML includes this annotation.
The output resembles
elb-id.elb.aws-region.amazonaws.com.
If you have created an externally-facing load balancer and you have access
to the public VPC subnet, you can connect to the load balancer with curl.
Replace external-ip with the IP from the output of
kubectl get service from the previous step.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Creating a load balancer\n\nThis topic shows you how to set up an AWS Elastic Load Balancer (ELB) with\nGKE on AWS.\n\nWhen you create a Service of type `LoadBalancer`, a GKE on AWS\ncontroller configures a\n[Classic](https://aws.amazon.com/elasticloadbalancing/features/) or\n[Network](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html)\nELB on AWS.\n\nYou can also follow the [Quickstart](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/quickstart) to create an\nexternally facing Classic ELB from the Google Cloud console or\n[Create an AWS Application Load Balancer (ALB)](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/loadbalancer-alb).\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- From your `anthos-aws` directory, use `anthos-gke` to switch context to your user cluster. \n\n ```sh\n cd anthos-aws\n env HTTPS_PROXY=http://localhost:8118 \\\n anthos-gke aws clusters get-credentials CLUSTER_NAME\n ```\n Replace \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e with your user cluster name.\n- Have the `curl` command line tool or a similar tool installed.\n\n### Selecting an external or internal load balancer\n\nGKE on AWS creates an external (in your public subnet) or\ninternal (in your private subnet) load balancer depending on\nan annotation to the LoadBalancer resource.\n\nIf you select an external load balancer, it is accessible by the IP addresses\nallowed in the node pool's\n[security groups](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/reference/security-groups)\nand the subnet's\n[network access control lists (ACLs)](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html).\n\n### Choosing a load balancer type\n\nChoose if you want to create a Classic Load Balancer (Classic ELB) or a\nNetwork Load Balancer (NLB). For more information on the differences between\nload balancer types, see\n[Load balancer types](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/load-balancer-types.html)\nin the AWS documentation.\n\nCreating a LoadBalancer\n-----------------------\n\nYou create a load balancer by creating a deployment and exposing that deployment\nwith a service.\n\n1. Create your deployment. Containers in this Deployment listen on port 50001.\n Save the following YAML to a file named `my-deployment-50001.yaml`:\n\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: my-deployment-50001\n spec:\n selector:\n matchLabels:\n app: products\n department: sales\n replicas: 3\n template:\n metadata:\n labels:\n app: products\n department: sales\n spec:\n containers:\n - name: hello\n image: \"gcr.io/google-samples/hello-app:2.0\"\n env:\n - name: \"PORT\"\n value: \"50001\"\n\n2. Create the Deployment with `kubectl apply`:\n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl apply -f my-deployment-50001.yaml\n\n3. Verify that three Pods are running:\n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl get pods --selector=app=products\n\n4. Create a Service of type `LoadBalancer` for your deployment. You can create\n a Classic or Network ELB on either your public or private subnet.\n Choose from one of the following options:\n\n - A Classic ELB on the public subnet\n - An NLB on the public subnet\n - A Classic ELB on the private subnet\n - An NLB on the private subnet\n\n Then, copy the following manifest to a file named `my-lb-service.yaml`. \n\n ### Classic Public\n\n apiVersion: v1\n kind: Service\n metadata:\n name: my-lb-service\n spec:\n type: LoadBalancer\n selector:\n app: products\n department: sales\n ports:\n - protocol: TCP\n port: 60000\n targetPort: 50001\n\n ### NLB Public\n\n You create a NLB by setting the annotation\n `service.beta.kubernetes.io/aws-load-balancer-type`\n to `nlb`. The following YAML includes this annotation.\n **Note:** You cannot apply the NLB annotation to an existing Service. To create an NLB, you must delete the existing external LoadBalancer and re-create it. \n\n apiVersion: v1\n kind: Service\n metadata:\n name: my-lb-service\n annotations:\n service.beta.kubernetes.io/aws-load-balancer-type: nlb\n spec:\n type: LoadBalancer\n selector:\n app: products\n department: sales\n ports:\n - protocol: TCP\n port: 60000\n targetPort: 50001\n\n ### Classic Private\n\n You create a private LoadBalancer by setting the annotation\n `service.beta.kubernetes.io/aws-load-balancer-internal`\n to `\"true\"`. The following YAML includes this annotation.\n **Note:** You cannot apply the internal load balancer annotation to an existing Service. To create an internal load balancer, you must delete the existing external LoadBalancer and re-create it. \n\n apiVersion: v1\n kind: Service\n metadata:\n name: my-lb-service\n annotations:\n service.beta.kubernetes.io/aws-load-balancer-internal: \"true\"\n spec:\n type: LoadBalancer\n selector:\n app: products\n department: sales\n ports:\n - protocol: TCP\n port: 60000\n targetPort: 50001\n\n ### NLB Private\n\n You create a private NLB by setting the annotations:\n - `service.beta.kubernetes.io/aws-load-balancer-internal` to `\"true\"`\n - `service.beta.kubernetes.io/aws-load-balancer-type` to `nlb`\n\n The following YAML includes both annotations.\n **Note:** You cannot apply these annotations to an existing Service. To create an internal NLB, you must delete the existing external LoadBalancer and re-create it. \n\n apiVersion: v1\n kind: Service\n metadata:\n name: my-lb-service\n annotations:\n service.beta.kubernetes.io/aws-load-balancer-internal: \"true\"\n service.beta.kubernetes.io/aws-load-balancer-type: nlb\n spec:\n type: LoadBalancer\n selector:\n app: products\n department: sales\n ports:\n - protocol: TCP\n port: 60000\n targetPort: 50001\n\n5. Create the Service with `kubectl apply`:\n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl apply -f my-lb-service.yaml\n\n | **Note:** Configuring the load balancer and IP address takes several minutes.\n6. View the Service's hostname with `kubectl get service`.\n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl get service my-lb-service \\\n --output jsonpath=\"{.status.loadBalancer.ingress..hostname}{'\\n'}\"\n\n The output resembles\n \u003cvar translate=\"no\"\u003eelb-id\u003c/var\u003e`.elb.`\u003cvar translate=\"no\"\u003eaws-region\u003c/var\u003e`.amazonaws.com`.\n7. If you have created an externally-facing load balancer and you have access\n to the public VPC subnet, you can connect to the load balancer with `curl`.\n Replace \u003cvar translate=\"no\"\u003eexternal-ip\u003c/var\u003e with the IP from the output of\n `kubectl get service` from the previous step.\n\n curl \u003cvar translate=\"no\"\u003eexternal-ip\u003c/var\u003e:60000\n\n The output resembles the following: \n\n Hello, world!\n Version: 2.0.0\n Hostname: my-deployment-50001-84b6dc5555-zmk7q\n\nCleaning up\n-----------\n\nTo remove the Service and Deployment, use `kubectl delete`. \n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl delete -f my-lb-service.yaml\n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl delete -f my-deployment-50001.yaml\n\nTroubleshooting\n---------------\n\nIf you cannot access a load balancer endpoint, try\n[tagging your subnets](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/troubleshooting#tagging_subnets).\n\nWhat's Next\n-----------\n\n- Follow the [Quickstart](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/quickstart) to create an\n externally facing Classic ELB from the Google Cloud console.\n\n- [Create an AWS Application Load Balancer (ALB)](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/loadbalancer-alb).\n\n- Read the GKE on Google Cloud documentation on\n [Exposing applications using services](/kubernetes-engine/docs/how-to/exposing-apps)."]]