O produto descrito nesta documentação, Anthos Clusters na AWS (geração anterior), está em modo de manutenção . Todas as novas instalações devem usar o produto da geração atual, Anthos Clusters na AWS .
No seu diretório anthos-aws , use anthos-gke para alternar o contexto para seu cluster de usuários.
cd anthos-aws
env HTTPS_PROXY=http://localhost:8118 \
anthos-gke aws clusters get-credentials CLUSTER_NAME
Substitua CLUSTER_NAME pelo nome do seu cluster de usuário.
Tenha a ferramenta de linha de comando curl ou uma ferramenta similar instalada.
Selecionando um balanceador de carga externo ou interno
O GKE na AWS cria um balanceador de carga externo (na sua sub-rede pública) ou interno (na sua sub-rede privada), dependendo de uma anotação no recurso LoadBalancer.
Escolha se deseja criar um Balanceador de Carga Clássico (ELB Clássico) ou um Balanceador de Carga de Rede (NLB). Para obter mais informações sobre as diferenças entre os tipos de balanceador de carga, consulte Tipos de balanceador de carga na documentação da AWS.
Criando um LoadBalancer
Você cria um balanceador de carga criando uma implantação e expondo essa implantação com um serviço.
Crie sua implantação. Os contêineres nesta implantação escutam na porta 50001. Salve o seguinte YAML em um arquivo chamado my-deployment-50001.yaml :
Crie um serviço do tipo LoadBalancer para sua implantação. Você pode criar um ELB clássico ou de rede na sua sub-rede pública ou privada. Escolha uma das seguintes opções:
Um ELB clássico na sub-rede pública
Um NLB na sub-rede pública
Um ELB clássico na sub-rede privada
Um NLB na sub-rede privada
Em seguida, copie o seguinte manifesto para um arquivo chamado my-lb-service.yaml .
Crie um LoadBalancer privado definindo a anotação service.beta.kubernetes.io/aws-load-balancer-internal como "true" . O YAML a seguir inclui essa anotação.
A saída se assemelha elb-id .elb. aws-region .amazonaws.com .
Se você criou um balanceador de carga externo e tem acesso à sub-rede pública da VPC, pode se conectar ao balanceador de carga com curl . Substitua external-ip pelo IP da saída do kubectl get service da etapa anterior.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-06-12 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)."]]