Produk yang dijelaskan dalam dokumentasi ini, Cluster Anthos di AWS (generasi sebelumnya), kini berada dalam mode pemeliharaan. Semua penginstalan baru harus menggunakan produk generasi saat ini, cluster Anthos di AWS.
Dari direktori anthos-aws, gunakan
anthos-gke untuk beralih konteks ke cluster pengguna Anda.
cd anthos-aws
env HTTPS_PROXY=http://localhost:8118 \
anthos-gke aws clusters get-credentials CLUSTER_NAME
Ganti CLUSTER_NAME dengan nama cluster pengguna Anda.
Sudah menginstal alat command line curl atau alat serupa.
Memilih load balancer eksternal atau internal
GKE di AWS membuat load balancer eksternal (di subnet publik Anda) atau internal (di subnet pribadi Anda) bergantung pada anotasi ke resource LoadBalancer.
Pilih apakah Anda ingin membuat Load Balancer Klasik (ELB Klasik) atau
Network Load Balancer (NLB). Untuk mengetahui informasi selengkapnya tentang perbedaan antara jenis load balancer, lihat Jenis load balancer dalam dokumentasi AWS.
Membuat LoadBalancer
Anda membuat load balancer dengan membuat deployment dan mengekspos deployment tersebut
dengan layanan.
Buat deployment Anda. Container dalam Deployment ini memproses port 50001.
Simpan YAML berikut ke file bernama my-deployment-50001.yaml:
Buat Service jenis LoadBalancer untuk deployment Anda. Anda dapat membuat
ELB Klasik atau Jaringan di subnet publik atau pribadi.
Pilih dari salah satu opsi berikut:
ELB Klasik di subnet publik
NLB di subnet publik
ELB Klasik di subnet pribadi
NLB di subnet pribadi
Kemudian, salin manifes berikut ke file bernama my-lb-service.yaml.
Anda membuat LoadBalancer pribadi dengan menyetel anotasi
service.beta.kubernetes.io/aws-load-balancer-internal
ke "true". YAML berikut menyertakan anotasi ini.
Outputnya akan terlihat seperti
elb-id.elb.aws-region.amazonaws.com.
Jika telah membuat load balancer yang menghadap ke luar dan memiliki akses
ke subnet VPC publik, Anda dapat terhubung ke load balancer dengan curl.
Ganti external-ip dengan IP dari output
kubectl get service dari langkah sebelumnya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-31 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)."]]