官术网_书友最值得收藏!

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:

  1. First of all, deploy a single replica nginx server by running its Docker image on port 80:
kubectl run nginx --image=nginx --port=80  
  1. 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
  1. 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  
  1. 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
  1. This will create an HTTP load balancer. Run the file using the following command:
kubectl apply -f basic-ingress.yaml  
  1. Now you can find out the external IP address of your load balancer by calling ingress service:
kubectl get ingress basic-ingress  
  1. To remove this load balancer, use the following command:
kubectl delete ingress basic-ingress
主站蜘蛛池模板: 福安市| 宁河县| 阿图什市| 新津县| 申扎县| 枞阳县| 新巴尔虎左旗| 长泰县| 年辖:市辖区| 简阳市| 吉林市| 宝丰县| 壤塘县| 泸州市| 晋宁县| 康保县| 南涧| 陆良县| 乌兰浩特市| 涟源市| 邻水| 永宁县| 棋牌| 江油市| 无锡市| 怀集县| 宜州市| 永登县| 铁岭县| 玉山县| 汕头市| 仪陇县| 达州市| 延长县| 伽师县| 泾阳县| 彝良县| 鄂伦春自治旗| 榕江县| 民丰县| 无极县|