In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The following brings you how to use httpd mirror to create a Deployment resource object and other associations, hoping to bring you some help in practical application. Load Balancer involves many things, but there are not many theories. There are many books on the Internet. Today, we will use the accumulated experience in the industry to make an answer.
1. Use httpd mirror to create a Deployment resource object [root@master ~]# vim lvjianzhao.yaml #Write yaml file kind: Deployment #Specify the resource object type to create apiVersion: extensions/v1beta1 #Specify the API version corresponding to deployment metadata: name: lvjianzhao-deploy #Define deployment name spec: replicas: 4 #define the number of pod copies to create template: metadata: labels: #Specify the label of the pod user: lvjianzhao spec: containers: - name: httpd #Specify container name image: httpd #Specify which mirror to run container on [root@master ~]# kubectl apply -f lvjianzhao.yaml #execute written file [root@master ~]# kubectl explain deployment #Note: If you don't know the API version corresponding to a resource object, you can check KIND: DeploymentVERSION: extensions/v1beta1 #This is the API version corresponding to the Deployment resource ........................# [root@master ~]# kubectl get deployment lvjianzhao-deploy #Make sure the yaml file executed generates the number of pods we need
Check if the pod label is the label we defined:
[root@master ~]# kubectl describe deployment lvjianzhao-deploy #View details of this resource object Name: lvjianzhao-deployNamespace: defaultCreationTimestamp: Thu, 07 Nov 2019 17:50:44 +0800Labels: "user=lvjianzhao" #This is the label of the resource object. 2. Create an svc resource object associated with the Deployment resource object. and can provide services to the external network. The mapping node port is: 32123.
[root@master ~]# vim httpd-service.yaml #Write yaml file for service kind: ServiceapiVersion: v1metadata: name: httpd-servicespec: type: NodePort #Type "NodePort" needs to be specified here, otherwise cluster IP selector is default: user: lvjianzhao #associate this label with the deployment resource object ports: - protocol: TCP port: 79 #Here specifies the port of the Cluster IP to map to targetPort: 80 #This specifies the port to map to pod nodePort: 32123 #This specifies the port mapped to the host [root@master ~]# kubectl apply -f httpd-service.yaml #execute the yaml file [root@master ~]# kubectl get svc httpd-service #View created svc (service) NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEhttpd-service NodePort 10.97.13.198 79:32123/TCP 2m1s #You can see that the specified cluster port is mapped to the local 32123
Now you can use client to access port 32123 of any node in the k8s cluster, and you can see the services provided by pod, as follows:
[root@master ~]# kubectl describe svc httpd-service #View details of this service
The information returned is as follows (only a few IPs are displayed, the rest are omitted, not unspecified):
Since it is mentioned above that the endpoint specified is the IP address of the backend pod, then check and verify whether it is correct, as follows:
[root@master ~]# kubectl get pod -o wide | awk '{print $6}' #Output IP address of backend pod IP10.244.1.1810.244.2.2110.244.1.1710.244.2.20 #You can confirm that the IP you are viewing corresponds to the IP specified in the endpoint of the service above
View the details of svc mapping endpoints and explain the underlying principles of Load Balancer.
3. After we finish the above operation, the client can access the services provided by our pod (and it is the effect of Load Balancer), so what kind of implementation process is this? Depends on what?
In fact, the principle behind it is not so high. Kube-proxy realizes the effect of Load Balancer through the forwarding mechanism of iptables. First define the target IP as the cluster IP provided by service, and then use the "-j" option to forward to other iptables rules, as follows:
[root@master ~]# kubectl get svc httpd-service |awk '{print $3}'#We need to see the cluster IPCLUSTER-IP to service first 10.97.13.198[root@master ~]# iptables-save > a.txt #Output iptables rule to file, so we can find [root@master ~]# vim a.txt #Open iptables rule
Searching for our cluster IP, we can see that when the destination address is a cluster IP address, it is forwarded to another rule "KUBE-SVC-X2P42VLQEZCHLPKZ", as follows:
So, now continue searching for the rules it forwards to, as follows:
In the above figure, it is the strategy related to his implementation of Load Balancer. We have a total of four pods, so the first rule in the above figure uses random algorithm. There is only a probability of 0.25 (1/4) to adopt this rule. When the second rule is reached, there is a probability of 0.33. Because after removing the previous pod, there are still three pods, 10/3=0.33. This is the origin of this probability. And so on, when the last rule is reached, Then there is no need to specify the probability, it must be processing this request.
Attach: label node nodes so that pods run on specified nodes. [root@master ~]# kubectl label nodes node01 disktype=ssd #Label node node01 "disktype=ssd"(custom label)#The corresponding yaml file is as follows: kind: DeploymentapiVersion: extensions/v1beta1metadata: name: httpdspec: revisionHistoryLimit: 10 replicas: 3 template: metadata: labels: app: httpd-server spec: containers: - name: httpd image: 192.168.1.1:5000/httpd:v1 ports: - containerPort: 80 nodeSelector: //Specify label selector
disktype: ssd
After reading the above on how to use httpd mirror to create a Deployment resource object and other associations, if you still have anything you need to know, you can find something you are interested in the industry information or find our professional technical engineers to answer. Technical engineers have more than ten years of experience in the industry.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.