Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use daemonset+hostport to implement ingress-like load balancing service

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

How to use daemonset+hostport to implement ingress-like load balancing service? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

In the kubernetes environment, now we provide services to the outside world, we use more ingress solutions. But for many users who have been using nginx as a reverse proxy for a long time, it is obviously troublesome to migrate complex configurations to nginx ingress.

Therefore, for a larger number of users, migrate the configuration information of nginx directly to the image, and then release it iteratively through good version management. This makes up for the disadvantage of manually mirroring and then releasing each update compared to ingress, and instead reflects the advantages of version management.

At the same time, with reference to the solutions of ingress controller from various manufacturers, daemonset+hostport can ensure that requests are sent to the corresponding reverse proxy faster and more directly, thus improving throughput efficiency.

Next, let's introduce how to use daemonset+hostport to implement ingress-like load balancing service.

1. Test site:

First of all, let's make two mirrors. If you visit, you will return foo1 and foo2.

two。 Publish the test site:

Foo1-pod.yaml

ApiVersion: v1kind: Podmetadata: name: mytest-site-foo1 labels: app: mytest-site-foo1spec: containers:-name: mytest-site-foo1 image: 192.168.1.242:5000/mytest-site-foo1

Foo1-svc.yaml

ApiVersion: v1kind: Servicemetadata: name: mytest-site-foo1-svc labels: app: mytest-site-foo1-svcspec: selector: app: mytest-site-foo1 type: ClusterIP ports:-protocol: TCP port: 8009 targetPort: 80

Then release kubectl apply-f foo1-pod.yaml;kubectl apply-f foo1-svc.yaml

Write the foo2-pod.yaml,foo2-svc.yaml according to the above file and publish it.

two。 Create a front-end nginx image:

Configuration file default.conf for nginx:

Server {listen 80; server_name localhost; # charset koi8-r; access_log / var/log/nginx/host.access.log main; location / foo1 {proxy_pass http://mytest-site-foo1-svc:8009/;} location / foo2 {proxy_pass http://mytest-site-foo2-svc:8009/;} location / {root / var/www/html;}}

Then write dockerfile (of course, if there are more configuration files, you can make directories and add them to the nginx image):

FROM nginx:latestADD default.conf / etc/nginx/conf.d/ENTRYPOINT nginx-c / etc/nginx/nginx.conf & & tail-f / dev/null

Create an image and upload it to registry:

Make mirror image: docker build-t mytest-site-nginx.

Play tag:docker tag mytest-site-nginx 192.168.1.244:5000/mytest-site-nginx

Upload: docker push 192.168.1.244:5000/mytest-site-nginx

3. Publish nginx

With the corresponding image, we can publish the nginx to each node as daemonset.

Mytest-site-nginx-ds.yaml:

ApiVersion: apps/v1kind: DaemonSetmetadata: name: mytest-site-nginx-ds labels: app: mytest-site-nginx-dsspec: template: metadata: labels: app: mytest-site-nginx-dsspec: containers:-name: mytest-site-nginx image: 192.168.1.242:5000/mytest-site-nginx:latest ports:-name: http hostPort: 80 Protocol: TCP containerPort: 80 selector: matchLabels: app: mytest-site-nginx-ds

Kubectl apply-f mytest-site-nginx-ds.yaml

Then we can access each node / foo1 and / foo2 using the http protocol to access the website that is actually running at the back end.

4. How to update

First put our dockerfile and configuration file on gitlab.

Implement at release time:

Download configuration code-> build image-> upload image-> kubectl set image to publish.

At the same time, you can use tag of git or roll back of kubernetes to roll back the version.

This is the answer to the question on how to use daemonset+hostport to implement ingress-like load balancing service. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report