In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about how to understand Traefik in K8s. Many people may not understand it very well. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Traefik is an open source reverse proxy and load balancing tool.
Its biggest advantage is that it can be directly integrated with common micro-service systems and can realize automatic dynamic configuration.
Docker, Swarm, Mesos/Marathon, Mesos, Kubernetes, Consul, Etcd, Zookeeper, BoltDB, Rest API and other back-end models are currently supported.
Why is it more biased towards domain Traefik? let's briefly compare it.
Ingress:
Use nginx as the front-end load balancer, constantly interact with kubernetes api through ingress controller to obtain real-time changes in the back-end service,pod, and then dynamically update the nginx configuration and refresh to make the configuration effective to achieve the purpose of service discovery.
Traefik:
Traefik itself is designed to interact with kubernetes api in real time, perceive changes in the back-end service,pod, and automatically update the configuration and reload.
Relatively speaking, traefik is faster and more convenient, and supports more features, which makes reverse proxy and load balancing more direct and efficient.
Ingress classified nginx ingresstraefix ingress protocols http https htt2 grpc tcp udphttp https htt2 grpc tcp+tls routes match host pathhost, path, headers, query, path prefix, method Namespace support-share or specify namespace deployment strategy-Canary deployment, blue-green deployment, grayscale deployment upstream probe retry, timeout, heartbeat probe retry, timeout, heartbeat probe, fuse load balancing algorithm RR, session persistence, minimum connection, minimum time, consistency hashWRR, dynamic RR, The advantage of session persistence is easy to use Easy to connect to Golang, easy to deploy, support many backends, built-in WebUI shortcomings do not solve nginx reload, there are many plug-ins, but there are no disadvantages in extended performance checking. The new version supports UDP.
Let's start with the traefick2.4.8 installation.
According to the traefik official website, https://doc.traefik.io/traefik/ traefik is installed in the following four ways
Use the official Docker image (using docker mirroring)
Use the Helm Chart (using helm)
Use the binary distribution (binary installation)
Compile your binary from the sources (source code compilation)
Of course, we choose helm mode. Helm is the package manager of K8s, which can be simply understood as the yum of linux. Let's install helm first.
Install Helm
Log on to the official website https://helm.sh/zh/docs/intro/quickstart/ to find the latest version. The latest stable version is 3.5.4.
Download helm3.4.5
Wget https://get.helm.sh/helm-v3.5.4-linux-amd64.tar.gz
Decompress helm
Tar-xzvf helm-v3.5.4-linux-amd64.tar.gz
Cd linux-amd64
Mv helm / usr/local/bin/
Running helm-- help displays the following to indicate that the installation is successful
Add helm repository, here add 2 (traefik and aliyun)
Helm repo add traefik https://helm.traefik.io/traefik
Helm repo add apphub https://apphub.aliyuncs.com/
Update repo warehouse resources
Helm repo update
Download the chart corresponding to traefik to the local
Helm pull traefik/traefik
Decompress traefik
Tar-xzvf traefik-9.19.0.tgz
Modify values.yaml (here is mainly to change the service type of traefik to NodePort-- and the original is LoadBalancer. In addition, the external http and https ports nodePort are also open. My side is set freely because the port is not occupied. Readers can modify it on their own.)
Create a traefik namespace (here I added a new namespace for ease of management, and readers can also install it under the default space, which I like)
Kubecl create-n traefik
Download traefik2.4.8 image
Docker pull traefik:2.4.8
The following message indicates that the installation was successful
Install the local traefik into the namespace traefik
Helm install traefik. / traefik/-n traefik
The following message indicates that the installation was successful
Traefik2.4.8 for security reasons, this HelmChart does not expose the Traefik dashboard by default. But we still have ways to look at it, such as creating an IngressRoute on the official website.
Vi traefik-dashboard.yaml
# dashboard.yamlapiVersion: traefik.containo.us/v1alpha1kind: IngressRoutemetadata: name: dashboardspec: entryPoints:-web routes:-match: PathPrefix (`/ dashboard`) | | PathPrefix (` / api`) kind: Rule services:-name: api@internal kind: TraefikService
Install (here I am still installed into the traefik namespace for easy management)
Kubectl apply-f traefik-dashboard.yaml-n traefik
The following interface indicates that the installation is successful
Let's create a nginx to test
Vi nginx-demo-ingress-route.yml
We create a nginx service and change the IngressRoute routing setting to'/ demo/'
ApiVersion: apps/v1kind: Deploymentmetadata: name: nginx labels: app: nginxspec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginxspec: containers:-name: nginx image: nginx:alpine volumeMounts:-name: timezone mountPath: / etc/localtime volumes:-name: timezone hostPath: Path: / usr/share/zoneinfo/Asia/Shanghai---apiVersion: v1kind: Servicemetadata: name: nginx-svcspec: ports:-port: 80 targetPort: 80 type: NodePort selector: app: nginx---apiVersion: traefik.containo.us/v1alpha1kind: IngressRoutemetadata: name: nginx-ingressroute namespace: defaultspec: entryPoints:-web routes:-match: PathPrefix (`/ demo/`) kind: Rule services:-name: nginx-svc port: 80
Download nginx image
Docker pull nginx:alpine
Installation
Kubectl apply-f nginx-demo-ingress-route.yml-n traefik
Then we see that the services of the dashboard interface has changed to 5 (the original is 4), and the number of route has changed from 3 to 4.
Open route to see the routing situation.
You can see that our new route is already in effect, so let's try to visit
Http://{ public network IP}: 32080/demo/
This indicates that the route takes effect, and our traefik installation is successful.
After reading the above, do you have any further understanding of the understanding of Traefik in K8s? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.