In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares to you is the example analysis of K8s using ingress-nginx load balancing. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.
Ingress-nginx load balancer call sequence: user-> ingress-nginx (pod)-- > ingress-nginx (controller)-> ingress--- > service--- > pod
1. Download and install ingress-nginx (layer 7 Scheduler)
Https://kubernetes.github.io/ingress-nginx/deploy/-detailed documentation
Https://github.com/kubernetes/ingress-nginx/tree/master/deploy-yaml file for ingress-nginx
[root@k8s1 ~] # kubectl explain ingress-help information
[root@k8s1 ~] # vim / etc/sysconfig/kubelet-enable ipvs function (there are three kinds of userspace,iptables,ipvs for service load balancer)
KUBE_PROXY_MODE=ipvs-add parameters
[root@k8s1] # kubectl apply-f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
[root@k8s1] # kubectl get pods-n ingress-nginx
NAME READY STATUS RESTARTS AGE
Nginx-ingress-controller-68db76b4db-pqcl7 0/1 ContainerCreating 0 35s
[root@k8s1] # kubectl get pods-n ingress-nginx
NAME READY STATUS RESTARTS AGE
Nginx-ingress-controller-68db76b4db-pqcl7 1/1 Running 0 9m20s
[root@k8s1 ~] #
two。 Create a service controller and three pod at the back end
[root@k8s1 ~] # vim service-pod.yaml
Kind: Service
Metadata:
Name: ingress-nginx
Namespace: ingress-nginx
Spec:
Selector:
App: ingress-nginx-keep one to the following pod
Release: canary
Ports:
-name: http
TargetPort: 80
Port: 80
-
ApiVersion: apps/v1
Kind: Deployment
Metadata:
Name: myapp-deploy-ng
Namespace: ingress-nginx
Spec:
Replicas: 3
Selector:
MatchLabels:
App: ingress-nginx-keep one to the service above
Release: canary
Template:
Metadata:
Labels:
App: ingress-nginx-keep one to the service above
Release: canary
Spec:
Containers:
-name: ingress-nginx-- maintain one to the above service
Image: ikubernetes/myapp:v1
Ports:
-name: http
ContainerPort: 80
[root@k8s1] # kubectl apply-f service-pod.yaml
Service/ingress-nginx created
Deployment.apps/myapp-deploy-ng created
[root@k8s1] # kubectl get pods-o wide-n ingress-nginx
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
Myapp-deploy-ng-65d64df569-5f9l2 1bat 1 Running 0 9m6s 10.244.2.9 k8s3
Myapp-deploy-ng-65d64df569-n288f 1/1 Running 0 9m6s 10.244.1.76 k8s2
Myapp-deploy-ng-65d64df569-vnrj5 1/1 Running 0 9m6s 10.244.1.77 k8s2
Nginx-ingress-controller-68db76b4db-d2h75 1/1 Running 0 18d 10.244.2.240 k8s3
[root@k8s1] # kubectl get svc-n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGE
Ingress-nginx ClusterIP 10.99.27.16 80/TCP 20s
3. Create service-nodeport
[root@k8s1 ~] # wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml
[root@k8s1 ~] # vim service-nodeport.yaml
ApiVersion: v1
Kind: Service
Metadata:
Name: ingress-nginx
Namespace: ingress-nginx
Spec:
Type: NodePort
Ports:
-name: http
Port: 80
TargetPort: 80
Protocol: TCP
NodePort: 30880
-name: https
Port: 443
TargetPort: 443
Protocol: TCP
NodePort: 30443
Selector:
App: ingress-nginx
[root@k8s1] # kubectl apply-f service-nodeport.yaml
Service/ingress-nginx configured
[root@k8s1] # kubectl get svc-n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGE
Ingress-nginx NodePort 10.99.27.16 80:30880/TCP,443:30443/TCP 11h
[root@k8s1] # kubectl describe svc ingress-nginx-n ingress-nginx
Name: ingress-nginx
Namespace: ingress-nginx
Labels:
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion": "v1", "kind": "Service", "metadata": {"annotations": {}, "name": "ingress-nginx", "namespace": "ingress-nginx"}, "spec": {"ports": [{"na..."
Selector: app=ingress-nginx
Type: NodePort
IP: 10.99.27.16
Port: http 80/TCP
TargetPort: 80/TCP
NodePort: http 30880/TCP
Endpoints: 10.244.1.76 80, 10.244.1.77, 80, 10.244.2.9, 80-- three pod addresses of the backend agent
Port: https 443/TCP
TargetPort: 443/TCP
NodePort: https 30443/TCP
Endpoints: 10.244.1.76:443,10.244.1.77:443,10.244.2.9:443
Session Affinity: None
External Traffic Policy: Cluster
Events:
[root@k8s1 ~] # curl http://172.16.8.12:30880
4. Create an ingress controller
[root@k8s1 ~] # cat ingress.yaml
ApiVersion: extensions/v1beta1
Kind: Ingress
Metadata:
Name: ingress-myapp
Namespace: default
Annotations:
Kubernetes.io/ingress.class: "nginx"
Spec:
Rules:
-host: myapp.magedu.com-- Domain name
Http:
Paths:
-path:
Backend:
ServiceName: ingress-nginx-- service name
ServicePort: 80
[root@k8s1] # kubectl apply-f ingress.yaml
Ingress.extensions/ingress-myapp created
[root@k8s1 ~] # kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
Ingress-myapp myapp.magedu.com 80 4s
[root@k8s1 ~] # kubectl describe ingress ingress-myapp-- View ingress-myapp details
[root@k8s1] # kubectl get pods-n ingress-nginx
NAME READY STATUS RESTARTS AGE
Nginx-ingress-controller-68db76b4db-d2h75 1/1 Running 0 18d
[root@k8s1] # kubectl exec-n ingress-nginx-it nginx-ingress-controller-68db76b4db-d2h75-/ bin/sh
$
5. Visit the web site
[root@k8s1 ~] # curl http://172.16.8.12:30880/hostname.html-the result returned is the hostname of the three pod
Myapp-deploy-ng-65d64df569-5f9l2
[root@k8s1 ~] # curl http://172.16.8.12:30880/hostname.html
Myapp-deploy-ng-65d64df569-5f9l2
[root@k8s1 ~] # curl http://172.16.8.12:30880/hostname.html
Myapp-deploy-ng-65d64df569-vnrj5
[root@k8s1 ~] # curl http://172.16.8.12:30880/hostname.html
Myapp-deploy-ng-65d64df569-vnrj5
[root@k8s1 ~] # curl http://172.16.8.12:30880/hostname.html
Myapp-deploy-ng-65d64df569-n288f
[root@k8s1 ~] #
The above is an example analysis of k8s using ingress-nginx load balancing. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.