- Google Cloud Platform for Architects
- Vitthal Srinivasan Janani Ravi Judy Raj
- 290字
- 2021-06-25 20:48:36
Load balancing
Load balancing is yet another area where working with Kubernetes Engine instances is rather more complicated than working with Compute Engine VMs. With the Kubernetes Engine, you can make use of network-level load balancing, which works just out of the box. However, remember that the higher up the OSI stack you go, the more sophisticated your load balancing becomes. Extending that logic, the most sophisticated form of load balancing is going to be HTTP load balancing. This is something that does not work all that simply with Kubernetes Engines. If you want to use HTTP load balancing with container instances, you are going to have to do some interfacing of your own with the Compute Engine load balancing infrastructure:
- First of all, deploy a single replica nginx server by running its Docker image on port 80:
kubectl run nginx --image=nginx --port=80
- Create a service resource to access nginx from your cluster. The NodePort type allows Kubernetes Engine to make your service available on a random high port number:
kubectl expose deployment nginx --target-port=80 --type=NodePort
- You can also verify the service creation. The following command should show you the name of the service and the port number it has been assigned:
kubectl get service nginx
- Now you need to create and save an ingress resource that will contain rules and configurations of HTTP traffic:
nano basic-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: basic-ingress
spec:
backend:
serviceName: nginx
- This will create an HTTP load balancer. Run the file using the following command:
kubectl apply -f basic-ingress.yaml
- Now you can find out the external IP address of your load balancer by calling ingress service:
kubectl get ingress basic-ingress
- To remove this load balancer, use the following command:
kubectl delete ingress basic-ingress
推薦閱讀
- Hands-On Data Structures and Algorithms with Rust
- Developing Mobile Games with Moai SDK
- Python數(shù)據(jù)分析、挖掘與可視化從入門到精通
- 數(shù)據(jù)庫開發(fā)實踐案例
- PySpark大數(shù)據(jù)分析與應(yīng)用
- Lean Mobile App Development
- Solaris操作系統(tǒng)原理實驗教程
- Python數(shù)據(jù)分析從小白到專家
- 區(qū)塊鏈+:落地場景與應(yīng)用實戰(zhàn)
- 機器學(xué)習(xí):實用案例解析
- 企業(yè)級大數(shù)據(jù)項目實戰(zhàn):用戶搜索行為分析系統(tǒng)從0到1
- SOLIDWORKS 2018中文版機械設(shè)計基礎(chǔ)與實例教程
- 領(lǐng)域驅(qū)動設(shè)計精粹
- ORACLE 11g權(quán)威指南
- 數(shù)據(jù)庫技術(shù)與應(yīng)用:SQL Server 2008