Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Load balancing jaringan
Topik ini menunjukkan cara menyiapkan load balancer L4 yang didukung oleh Azure Standard Load Balancer menggunakan GKE di Azure .
Saat Anda membuat Service jenis LoadBalancer, pengontrol GKE di Azure akan mengonfigurasi Azure Load Balancer.
Sebelum memulai
Anda harus Membuat cluster
dan mengonfigurasi kubectl untuk mengakses cluster.
Memilih load balancer publik atau pribadi
Load balancer layanan dapat berupa publik — memiliki IP frontend publik
— atau internal — hanya dapat diakses melalui IP pribadi.
Secara default, Layanan baru bersifat publik. Untuk membuat load balancer internal, Anda menetapkan anotasi service.beta.kubernetes.io/azure-load-balancer-internal ke "true" dalam manifes.
Memilih subnet untuk load balancer internal
Saat membuat load balancer internal, GKE di Azure perlu memilih subnet untuk menempatkan load balancer. Subnet load balancer layanan default ini dipilih dari parameter pembuatan cluster sebagai berikut:
Jika ditentukan dan tidak kosong, cluster.networking.serviceLoadBalancerSubnetId
Jika tidak, cluster.controlPlane.subnetId
Atau, Anda dapat menentukan subnet yang akan digunakan untuk load balancer tertentu dengan
menambahkan anotasi service.beta.kubernetes.io/azure-load-balancer-internal-subnet
ke Layanan. Nilai untuk anotasi ini adalah nama subnet.
Membuat contoh 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
Azure Standard Load Balancer yang bersifat publik atau internal.
Pilih salah satu opsi berikut.
Salin salah satu manifes berikut ke file bernama my-lb-service.yaml.
Anda membuat LoadBalancer internal dengan menyetel anotasi
service.beta.kubernetes.io/azure-load-balancer-internal
ke "true". YAML berikut menyertakan anotasi ini.
yaml
apiVersion: v1
kind: Service
metadata:
name: my-lb-service
annotations:
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
type: LoadBalancer
selector:
app: products
department: sales
ports:
- protocol: TCP
port: 60000
targetPort: 50001
Buat Layanan dengan kubectl apply:
kubectlapply-fmy-lb-service.yaml
Lihat alamat Layanan dengan kubectl get service.
kubectlgetservicemy-lb-service
Output akan menyertakan kolom EXTERNAL-IP dengan alamat
load balancer (baik publik maupun pribadi, bergantung pada cara load balancer
dibuat).
Jika telah membuat load balancer publik, Anda dapat terhubung ke load balancer dengan curl. Ganti external-ip dengan alamat
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,["# Network load balancing\n======================\n\nThis topic shows you how to set up an L4 load balancer backed\nby an Azure Standard Load Balancer using GKE on Azure .\n\nWhen you create a Service of type `LoadBalancer`, a GKE on Azure\ncontroller configures an\n[Azure Load Balancer](https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-overview).\n\nBefore you begin\n----------------\n\n- You must [Create a cluster](/kubernetes-engine/multi-cloud/docs/azure/how-to/create-cluster) and configure `kubectl` to access the cluster.\n\nSelecting a public or private load balancer\n-------------------------------------------\n\nService load balancers can be either public --- having public frontend IPs\n--- or internal--- only accessible through private IPs.\n\nBy default, a new Service is public. To create an internal load\nbalancer, you set the `service.beta.kubernetes.io/azure-load-balancer-internal`\nannotation to `\"true\"` in your manifest.\n\nChoosing subnet for internal load balancers\n-------------------------------------------\n\nWhen creating an internal load balancer, GKE on Azure needs to pick\nthe subnet to place the load balancer in. This default service load balancer\nsubnet is chosen from the cluster's creation parameters as follows:\n\n1. If specified and non-empty, `cluster.networking.serviceLoadBalancerSubnetId`\n2. Otherwise, `cluster.controlPlane.subnetId`\n\nAlternately, you can specify the subnet to use for a given load balancer by\nadding the `service.beta.kubernetes.io/azure-load-balancer-internal-subnet`\nannotation to the Service. The value for this annotation is the subnet's name.\n\nCreating an example 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 kubectl apply -f my-deployment-50001.yaml\n\n3. Verify that three Pods are running:\n\n kubectl get pods --selector=app=products\n\n4. Create a Service of type `LoadBalancer` for your deployment. You can create\n an Azure Standard Load Balancer that is either public, or internal.\n Choose from one of the following options.\n\n Copy one of the following manifests to a file named `my-lb-service.yaml`. \n\n ### 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 ### Internal\n\n You create an internal LoadBalancer by setting the annotation\n `service.beta.kubernetes.io/azure-load-balancer-internal`\n to `\"true\"`. The following YAML includes this annotation.\n `yaml\n apiVersion: v1\n kind: Service\n metadata:\n name: my-lb-service\n annotations:\n service.beta.kubernetes.io/azure-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`\n5. Create the Service with `kubectl apply`:\n\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 address with `kubectl get service`.\n\n kubectl get service my-lb-service\n\n The output will include a column `EXTERNAL-IP` with an address of the\n load balancer (either public or private depending how the load balancer was\n created).\n7. If you have created a public load balancer you can connect to the\n load balancer with `curl`. Replace \u003cvar translate=\"no\"\u003eexternal-ip\u003c/var\u003e with the address\n from the output of `kubectl get service` from the previous step.\n\n curl http://\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\n### Cleaning up\n\nTo remove the Service and Deployment, use `kubectl delete`. \n\n kubectl delete -f my-lb-service.yaml\n kubectl delete -f my-deployment-50001.yaml"]]