NodePort在暴露服务时,会监听一个NodePort端口,且多个服务无法使用同一个端口的情况。 因此我们说Service可以理解为四层代理。说白了,就是基于IP:PORT的方式进行代理。 假设"v1.oldboyedu.com"的服务需要监听80端口,而"v2.oldboyedu.com"和"v3.oldboyedu.com"同时也需要监听80端口,svc就很难实现。 这个时候,我们可以借助Ingress来实现此功能,可以将Ingress看做七层代理,底层依旧基于svc进行路由。 而Ingress在K8S是内置的资源,表示主机到svc的解析规则,但具体实现需要安装附加组件(对应的是IngressClass),比如ingress-nginx,traefik等。 IngressClass和Ingress的关系优点类似于: nginx和nginx.conf的关系。
[root@master231 25-ingresses]# cat > 01-deploy-svc-xiuxian.yaml <<EOF apiVersion: apps/v1 kind: Deployment metadata: name: deploy-xiuxian-v1 spec: replicas: 3 selector: matchLabels: apps: v1 template: metadata: labels: apps: v1 spec: containers: - name: c1 image: registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v1 ports: - containerPort: 80 --- apiVersion: apps/v1 kind: Deployment metadata: name: deploy-xiuxian-v2 spec: replicas: 3 selector: matchLabels: apps: v2 template: metadata: labels: apps: v2 spec: containers: - name: c1 image: registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v2 ports: - containerPort: 80 --- apiVersion: apps/v1 kind: Deployment metadata: name: deploy-xiuxian-v3 spec: replicas: 3 selector: matchLabels: apps: v3 template: metadata: labels: apps: v3 spec: containers: - name: c1 image: registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v3 ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: svc-xiuxian-v1 spec: type: ClusterIP selector: apps: v1 ports: - port: 80 --- apiVersion: v1 kind: Service metadata: name: svc-xiuxian-v2 spec: type: ClusterIP selector: apps: v2 ports: - port: 80 --- apiVersion: v1 kind: Service metadata: name: svc-xiuxian-v3 spec: type: ClusterIP selector: apps: v3 ports: - port: 80 EOF [root@master231 25-ingresses]# kubectl apply -f 01-deploy-svc-xiuxian.yaml deployment.apps/deploy-xiuxian-v1 created deployment.apps/deploy-xiuxian-v2 created deployment.apps/deploy-xiuxian-v3 created service/svc-xiuxian-v1 created service/svc-xiuxian-v2 created service/svc-xiuxian-v3 created [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl get pods -o wide --show-labels NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS deploy-xiuxian-v1-6bc556784f-28h62 1/1 Running 0 33s 10.100.2.186 worker233 <none> <none> apps=v1,pod-template-hash=6bc556784f deploy-xiuxian-v1-6bc556784f-4wc6d 1/1 Running 0 33s 10.100.2.185 worker233 <none> <none> apps=v1,pod-template-hash=6bc556784f deploy-xiuxian-v1-6bc556784f-ntmlq 1/1 Running 0 33s 10.100.1.32 worker232 <none> <none> apps=v1,pod-template-hash=6bc556784f deploy-xiuxian-v2-64bb8c9785-ck9jd 1/1 Running 0 33s 10.100.2.189 worker233 <none> <none> apps=v2,pod-template-hash=64bb8c9785 deploy-xiuxian-v2-64bb8c9785-cq5s6 1/1 Running 0 33s 10.100.2.188 worker233 <none> <none> apps=v2,pod-template-hash=64bb8c9785 deploy-xiuxian-v2-64bb8c9785-jtxn8 1/1 Running 0 33s 10.100.1.34 worker232 <none> <none> apps=v2,pod-template-hash=64bb8c9785 deploy-xiuxian-v3-698c86cf85-dm72r 1/1 Running 0 33s 10.100.2.187 worker233 <none> <none> apps=v3,pod-template-hash=698c86cf85 deploy-xiuxian-v3-698c86cf85-jpz5j 1/1 Running 0 33s 10.100.1.35 worker232 <none> <none> apps=v3,pod-template-hash=698c86cf85 deploy-xiuxian-v3-698c86cf85-kzp8g 1/1 Running 0 33s 10.100.1.33 worker232 <none> <none> apps=v3,pod-template-hash=698c86cf85 [root@master231 25-ingresses]#
[root@master231 25-ingresses]# cat > 02-ingress-xiuxian.yaml <<EOF apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-xiuxian spec: # 指定IngressClass的名称 ingressClassName: nginx # 定义解析规则 rules: # 定义的是主机名 - host: v1.oldboyedu.com # 配置http协议 http: # 配置访问路径 paths: # 配置匹配用户访问的类型,表示前缀匹配 - pathType: Prefix # 指定匹配的路径 path: / # 配置后端的调度svc backend: # 配置svc的名称及端口 service: name: svc-xiuxian-v1 port: number: 80 - host: v2.oldboyedu.com http: paths: - pathType: Prefix backend: service: name: svc-xiuxian-v2 port: number: 80 path: / - host: v3.oldboyedu.com http: paths: - pathType: Prefix backend: service: name: svc-xiuxian-v3 port: number: 80 path: / EOF
[root@master231 25-ingresses]# kubectl apply -f 02-ingress-xiuxian.yaml ingress.networking.k8s.io/ingress-xiuxian created [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE ingress-xiuxian nginx v1.oldboyedu.com,v2.oldboyedu.com,v3.oldboyedu.com 80 4s [root@master231 25-ingresses]# [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl describe ingress ingress-xiuxian Name: ingress-xiuxian Labels: <none> Namespace: default Address: Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>) Rules: Host Path Backends ---- ---- -------- v1.oldboyedu.com / svc-xiuxian-v1:80 (10.100.1.32:80,10.100.2.185:80,10.100.2.186:80) v2.oldboyedu.com / svc-xiuxian-v2:80 (10.100.1.34:80,10.100.2.188:80,10.100.2.189:80) v3.oldboyedu.com / svc-xiuxian-v3:80 (10.100.1.33:80,10.100.1.35:80,10.100.2.187:80) Annotations: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Sync 12s nginx-ingress-controller Scheduled for sync Normal Sync 12s nginx-ingress-controller Scheduled for sync [root@master231 25-ingresses]#
10.0.0.232 v1.oldboyedu.com v2.oldboyedu.com 10.0.0.233 v3.oldboyedu.com
或者: 10.0.0.150 v1.oldboyedu.com v2.oldboyedu.com v3.oldboyedu.com
http://v1.oldboyedu.com/ http://v2.oldboyedu.com/ http://v3.oldboyedu.com/
[root@master231 25-ingresses]# kubectl get pods -o wide -n ingress-nginx NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES ingress-server-ingress-nginx-controller-58m2j 1/1 Running 0 174m 10.0.0.233 worker233 <none> <none> ingress-server-ingress-nginx-controller-hfrrc 1/1 Running 0 174m 10.0.0.232 worker232 <none> <none> [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl -n ingress-nginx exec -it ingress-server-ingress-nginx-controller-58m2j -- bash bash-5.1$ grep oldboyedu.com /etc/nginx/nginx.conf ## start server v1.oldboyedu.com server_name v1.oldboyedu.com ; ## end server v1.oldboyedu.com ## start server v2.oldboyedu.com server_name v2.oldboyedu.com ; ## end server v2.oldboyedu.com ## start server v3.oldboyedu.com server_name v3.oldboyedu.com ; ## end server v3.oldboyedu.com bash-5.1$ exit [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl delete ingress ingress-xiuxian ingress.networking.k8s.io "ingress-xiuxian" deleted [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl -n ingress-nginx exec -it ingress-server-ingress-nginx-controller-58m2j -- bash bash-5.1$ grep oldboyedu.com /etc/nginx/nginx.conf bash-5.1$
[root@master231 25-ingresses]# cat > 03-ingress-xiuxian-uri.yaml <<EOF apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-xiuxian-uri spec: ingressClassName: nginx rules: - host: xiuxian.oldboyedu.com http: paths: - pathType: Prefix path: /v1 backend: service: name: svc-xiuxian-v1 port: number: 80 - pathType: Prefix path: /v2 backend: service: name: svc-xiuxian-v2 port: number: 80 - pathType: Prefix path: /v3 backend: service: name: svc-xiuxian-v3 port: number: 80 EOF
[root@master231 25-ingresses]# kubectl apply -f 03-ingress-xiuxian-uri.yaml ingress.networking.k8s.io/ingress-xiuxian-uri created [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE ingress-xiuxian-uri nginx xiuxian.oldboyedu.com 80 4s [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl describe ingress ingress-xiuxian-uri Name: ingress-xiuxian-uri Labels: <none> Namespace: default Address: Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>) Rules: Host Path Backends ---- ---- -------- xiuxian.oldboyedu.com /v1 svc-xiuxian-v1:80 (10.100.1.37:80,10.100.2.191:80,10.100.2.192:80) /v2 svc-xiuxian-v2:80 (10.100.1.36:80,10.100.2.190:80,10.100.2.193:80) /v3 svc-xiuxian-v3:80 (10.100.1.38:80,10.100.1.39:80,10.100.2.194:80) Annotations: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Sync 9s nginx-ingress-controller Scheduled for sync Normal Sync 9s nginx-ingress-controller Scheduled for sync [root@master231 25-ingresses]#
[root@master231 25-ingresses]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES deploy-xiuxian-v1-6bc556784f-28cx8 1/1 Running 0 2m9s 10.100.2.191 worker233 <none> <none> deploy-xiuxian-v1-6bc556784f-djwzs 1/1 Running 0 2m9s 10.100.2.192 worker233 <none> <none> deploy-xiuxian-v1-6bc556784f-t4p84 1/1 Running 0 2m9s 10.100.1.37 worker232 <none> <none> deploy-xiuxian-v2-64bb8c9785-mht58 1/1 Running 0 2m9s 10.100.2.193 worker233 <none> <none> deploy-xiuxian-v2-64bb8c9785-s8xqh 1/1 Running 0 2m9s 10.100.2.190 worker233 <none> <none> deploy-xiuxian-v2-64bb8c9785-s8zfh 1/1 Running 0 2m9s 10.100.1.36 worker232 <none> <none> deploy-xiuxian-v3-698c86cf85-c8jpb 1/1 Running 0 2m9s 10.100.2.194 worker233 <none> <none> deploy-xiuxian-v3-698c86cf85-h42pf 1/1 Running 0 2m9s 10.100.1.38 worker232 <none> <none> deploy-xiuxian-v3-698c86cf85-jzm8r 1/1 Running 0 2m9s 10.100.1.39 worker232 <none> <none> [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl scale deployment deploy-xiuxian-v1 --replicas=1 deployment.apps/deploy-xiuxian-v1 scaled [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl scale deployment deploy-xiuxian-v2 --replicas=1 deployment.apps/deploy-xiuxian-v2 scaled [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl scale deployment deploy-xiuxian-v3 --replicas=1 deployment.apps/deploy-xiuxian-v3 scaled [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES deploy-xiuxian-v1-6bc556784f-t4p84 1/1 Running 0 2m35s 10.100.1.37 worker232 <none> <none> deploy-xiuxian-v2-64bb8c9785-s8zfh 1/1 Running 0 2m35s 10.100.1.36 worker232 <none> <none> deploy-xiuxian-v3-698c86cf85-c8jpb 1/1 Running 0 2m35s 10.100.2.194 worker233 <none> <none> [root@master231 25-ingresses]#
[root@master231 25-ingresses]# kubectl exec -it deploy-xiuxian-v1-6bc556784f-t4p84 -- sh / # mkdir /usr/share/nginx/html/v1 / # / # / # echo "<h1 style='color: red;'>www.oldboyedu.com</h1>" > /usr/share/nginx/html/v1/index.html / # / # cat /usr/share/nginx/html/v1/index.html <h1 style='color: red;'>www.oldboyedu.com</h1> / # [root@master231 25-ingresses]# kubectl exec -it deploy-xiuxian-v2-64bb8c9785-s8zfh -- sh / # mkdir /usr/share/nginx/html/v2 / # echo "<h1 style='color: green;'>www.oldboyedu.com</h1>" > /usr/share/nginx/html/v2/index.html / # cat /usr/share/nginx/html/v2/index.html <h1 style='color: green;'>www.oldboyedu.com</h1> / # [root@master231 25-ingresses]# kubectl exec -it deploy-xiuxian-v3-698c86cf85-c8jpb -- sh / # mkdir /usr/share/nginx/html/v3 / # / # echo "<h1 style='color: pink;'>www.oldboyedu.com</h1>" > /usr/share/nginx/html/v3/index.html / # / # cat /usr/share/nginx/html/v3/index.html <h1 style='color: pink;'>www.oldboyedu.com</h1> / #
http://xiuxian.oldboyedu.com/v1/ http://xiuxian.oldboyedu.com/v2/ http://xiuxian.oldboyedu.com/v3/
[root@master231 25-ingresses]# openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=www.yinzhengjie.com" [root@master231 25-ingresses]# [root@master231 25-ingresses]# ll tls.* -rw-r--r-- 1 root root 1139 Jul 28 15:47 tls.crt -rw------- 1 root root 1704 Jul 28 15:47 tls.key [root@master231 25-ingresses]#
[root@master231 25-ingresses]# kubectl create secret tls ca-secret --cert=tls.crt --key=tls.key secret/ca-secret created [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl get secrets ca-secret NAME TYPE DATA AGE ca-secret kubernetes.io/tls 2 10s [root@master231 25-ingresses]#
[root@master231 25-ingresses]# cat > 04-deploy-apple.yaml <<EOF apiVersion: apps/v1 kind: Deployment metadata: name: deployment-apple spec: replicas: 3 selector: matchLabels: apps: apple template: metadata: labels: apps: apple spec: containers: - name: apple image: registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:apple ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: svc-apple spec: selector: apps: apple ports: - protocol: TCP port: 80 targetPort: 80 EOF [root@master231 25-ingresses]# kubectl apply -f 04-deploy-apple.yaml deployment.apps/deployment-apple created service/svc-apple created [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl get pods -l apps=apple -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES deployment-apple-5496cd9b6c-dxjqc 1/1 Running 0 9s 10.100.2.195 worker233 <none> <none> deployment-apple-5496cd9b6c-qwzhz 1/1 Running 0 9s 10.100.2.196 worker233 <none> <none> deployment-apple-5496cd9b6c-wxf5v 1/1 Running 0 9s 10.100.1.40 worker232 <none> <none> [root@master231 25-ingresses]#
[root@master231 25-ingresses]# cat > 05-ingress-tls.yaml <<EOF apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-tls-https # 如果指定了"ingressClassName"参数,就不需要在这里重复声明啦。 # 如果你的K8S 1.22- 版本,则使用注解的方式进行传参即可。 #annotations: # kubernetes.io/ingress.class: "nginx" spec: # 指定Ingress Class,要求你的K8S 1.22+ ingressClassName: nginx rules: - host: www.yinzhengjie.com http: paths: - backend: service: name: svc-apple port: number: 80 path: / pathType: ImplementationSpecific # 配置https证书 tls: - hosts: - www.yinzhengjie.com secretName: ca-secret EOF [root@master231 25-ingresses]# kubectl apply -f 05-ingress-tls.yaml ingress.networking.k8s.io/ingress-tls-https created [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl get ingress ingress-tls-https NAME CLASS HOSTS ADDRESS PORTS AGE ingress-tls-https nginx www.yinzhengjie.com 80, 443 13s [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl describe ingress ingress-tls-https Name: ingress-tls-https Labels: <none> Namespace: default Address: Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>) TLS: ca-secret terminates www.yinzhengjie.com Rules: Host Path Backends ---- ---- -------- www.yinzhengjie.com / svc-apple:80 (10.100.1.40:80,10.100.2.195:80,10.100.2.196:80) Annotations: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Sync 16s nginx-ingress-controller Scheduled for sync Normal Sync 16s nginx-ingress-controller Scheduled for sync [root@master231 25-ingresses]#
10.0.0.233 www.yinzhengjie.com
https://www.yinzhengjie.com/ 温馨提示: 如果google浏览器自建证书不认可,可以用鼠标在空白处单击左键,而后输入:"thisisunsafe",就会自动跳转。 当然,如果不想打这个代码,可以使用火狐浏览器打开即可。
参考链接: https://doc.traefik.io/traefik/getting-started/install-traefik/#use-the-helm-chart
[root@master231 traefik]# helm repo add traefik https://traefik.github.io/charts "traefik" has been added to your repositories [root@master231 traefik]# [root@master231 traefik]# helm repo list NAME URL oldboyedu-ingress https://kubernetes.github.io/ingress-nginx traefik https://traefik.github.io/charts [root@master231 traefik]#
[root@master231 traefik]# helm repo update Hang tight while we grab the latest from your chart repositories... ...Successfully got an update from the "oldboyedu-ingress" chart repository ...Successfully got an update from the "traefik" chart repository Update Complete. ⎈Happy Helming!⎈ [root@master231 traefik]#
[root@master231 traefik]# helm search repo traefik NAME CHART VERSION APP VERSION DESCRIPTION azure/traefik 1.87.7 1.7.26 DEPRECATED - A Traefik based Kubernetes ingress... traefik/traefik 36.0.0 v3.4.1 A Traefik based Kubernetes ingress controller traefik/traefik-crds 1.8.1 A Traefik based Kubernetes ingress controller traefik/traefik-hub 4.2.0 v2.11.0 Traefik Hub Ingress Controller traefik/traefik-mesh 4.1.1 v1.4.8 Traefik Mesh - Simpler Service Mesh traefik/traefikee 4.2.3 v2.12.4 Traefik Enterprise is a unified cloud-native ne... traefik/maesh 2.1.2 v1.3.2 Maesh - Simpler Service Mesh [root@master231 traefik]# [root@master231 traefik]# helm pull traefik/traefik [root@master231 traefik]# [root@master231 traefik]# ll total 260 drwxr-xr-x 2 root root 4096 Jul 28 16:13 ./ drwxr-xr-x 4 root root 4096 Jul 28 16:11 ../ -rw-r--r-- 1 root root 257573 Jul 28 16:13 traefik-36.3.0.tgz [root@master231 traefik]# [root@master231 traefik]# tar xf traefik-36.3.0.tgz [root@master231 traefik]# [root@master231 traefik]# ll total 264 drwxr-xr-x 3 root root 4096 Jul 28 16:14 ./ drwxr-xr-x 4 root root 4096 Jul 28 16:11 ../ drwxr-xr-x 4 root root 4096 Jul 28 16:14 traefik/ -rw-r--r-- 1 root root 257573 Jul 28 16:13 traefik-36.3.0.tgz [root@master231 traefik]# [root@master231 traefik]# helm install traefik-server traefik NAME: traefik-server LAST DEPLOYED: Mon Jul 28 16:14:30 2025 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: traefik-server with docker.io/traefik:v3.4.3 has been deployed successfully on default namespace ! [root@master231 traefik]# [root@master231 traefik]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION traefik-server default 1 2025-07-28 16:14:30.08425946 +0800 CST deployed traefik-36.3.0 v3.4.3 [root@master231 traefik]#
[root@master231 traefik]# kubectl get ingressclass,deploy,svc,po -o wide NAME CONTROLLER PARAMETERS AGE ingressclass.networking.k8s.io/nginx k8s.io/ingress-nginx <none> 4h29m ingressclass.networking.k8s.io/traefik-server traefik.io/ingress-controller <none> 5m5s NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR deployment.apps/traefik-server 1/1 1 1 5m5s traefik-server docker.io/traefik:v3.4.3 app.kubernetes.io/instance=traefik-server-default,app.kubernetes.io/name=traefik NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 3d5h <none> service/traefik-server LoadBalancer 10.200.224.167 10.0.0.152 80:12742/TCP,443:19345/TCP 5m5s app.kubernetes.io/instance=traefik-server-default,app.kubernetes.io/name=traefik NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/traefik-server-56846685f9-x5ws4 1/1 Running 0 5m5s 10.100.2.197 worker233 <none> <none> [root@master231 traefik]#
温馨提示: 如果无法下载镜像,则需要你手动下载。 SVIP直接来我的仓库获取: http://192.168.21.253/Resources/Kubernetes/Add-ons/traefik/
5.创建测试案例
[root@master231 25-ingresses]# kubectl apply -f 01-deploy-svc-xiuxian.yaml deployment.apps/deploy-xiuxian-v1 created deployment.apps/deploy-xiuxian-v2 created deployment.apps/deploy-xiuxian-v3 created service/svc-xiuxian-v1 created service/svc-xiuxian-v2 created service/svc-xiuxian-v3 created [root@master231 25-ingresses]# [root@master231 25-ingresses]# cat 02-ingress-xiuxian.yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-xiuxian spec: # 指定IngressClass的名称,不使用之前的Ingress-nginx,而是使用Traefik。 # ingressClassName: nginx ingressClassName: traefik-server rules: - host: v1.oldboyedu.com http: paths: - pathType: Prefix path: / backend: service: name: svc-xiuxian-v1 port: number: 80 - host: v2.oldboyedu.com http: paths: - pathType: Prefix backend: service: name: svc-xiuxian-v2 port: number: 80 path: / - host: v3.oldboyedu.com http: paths: - pathType: Prefix backend: service: name: svc-xiuxian-v3 port: number: 80 path: / [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl apply -f 02-ingress-xiuxian.yaml ingress.networking.k8s.io/ingress-xiuxian created [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl describe -f 02-ingress-xiuxian.yaml Name: ingress-xiuxian Labels: <none> Namespace: default Address: 10.0.0.152 Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>) Rules: Host Path Backends ---- ---- -------- v1.oldboyedu.com / svc-xiuxian-v1:80 (10.100.1.43:80,10.100.2.198:80,10.100.2.199:80) v2.oldboyedu.com / svc-xiuxian-v2:80 (10.100.1.41:80,10.100.1.42:80,10.100.2.200:80) v3.oldboyedu.com / svc-xiuxian-v3:80 (10.100.1.44:80,10.100.2.201:80,10.100.2.202:80) Annotations: <none> Events: <none> [root@master231 25-ingresses]# [root@master231 25-ingresses]# kubectl get ingress ingress-xiuxian NAME CLASS HOSTS ADDRESS PORTS AGE ingress-xiuxian traefik-server v1.oldboyedu.com,v2.oldboyedu.com,v3.oldboyedu.com 10.0.0.152 80 79s [root@master231 25-ingresses]# [root@master231 25-ingresses]# curl -H "HOST: v1.oldboyedu.com" http://10.0.0.152/ <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v1</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: green">凡人修仙传 v1 </h1> <div> <img src="1.jpg"> <div> </body> </html> [root@master231 25-ingresses]# [root@master231 25-ingresses]# curl -H "HOST: v2.oldboyedu.com" http://10.0.0.152/ <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v2</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: red">凡人修仙传 v2 </h1> <div> <img src="2.jpg"> <div> </body> </html> [root@master231 25-ingresses]# [root@master231 25-ingresses]# curl -H "HOST: v3.oldboyedu.com" http://10.0.0.152/ <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v3</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: pink">凡人修仙传 v3 </h1> <div> <img src="3.jpg"> <div> </body> </html> [root@master231 25-ingresses]#
[root@master231 helm]# vim traefik/values.yaml ... 187 ingressRoute: 188 dashboard: 189 # -- Create an IngressRoute for the dashboard 190 # enabled: false 191 enabled: true
[root@master231 traefik]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION traefik-server default 1 2025-07-28 16:14:30.08425946 +0800 CST deployed traefik-36.3.0 v3.4.3 [root@master231 traefik]# [root@master231 traefik]# helm uninstall traefik-server release "traefik-server" uninstalled [root@master231 traefik]# [root@master231 traefik]# helm install traefik-server traefik NAME: traefik-server LAST DEPLOYED: Mon Jul 28 16:29:05 2025 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: traefik-server with docker.io/traefik:v3.4.3 has been deployed successfully on default namespace ! [root@master231 traefik]# [root@master231 traefik]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION traefik-server default 1 2025-07-28 16:29:05.025166045 +0800 CST deployed traefik-36.3.0 v3.4.3 [root@master231 traefik]# [root@master231 traefik]#
[root@master231 traefik]# kubectl get pods -l app.kubernetes.io/name=traefik -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES traefik-server-74654b469d-zrx9c 1/1 Running 0 20s 10.100.203.156 worker232 <none> <none> [root@master231 traefik]# [root@master231 traefik]# cat > 01-svc-ing-traefik-dashboard.yaml <<EOF apiVersion: v1 kind: Service metadata: name: jiege-traefik-dashboard spec: ports: - name: dashboard port: 8080 selector: app.kubernetes.io/name: traefik type: ClusterIP --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-traefik-dashboard spec: ingressClassName: traefik-server rules: - host: traefik.oldboyedu.com http: paths: - pathType: Prefix path: / backend: service: name: jiege-traefik-dashboard port: number: 8080 EOF [root@master231 traefik]# kubectl apply -f 01-svc-ing-traefik-dashboard.yaml service/jiege-traefik-dashboard created ingress.networking.k8s.io/ingress-traefik-dashboard created [root@master231 traefik]# [root@master231 traefik]# kubectl get ingress ingress-traefik-dashboard NAME CLASS HOSTS ADDRESS PORTS AGE ingress-traefik-dashboard traefik-server traefik.oldboyedu.com 10.0.0.152 80 7s [root@master231 traefik]#
10.0.0.152 traefik.oldboyedu.com
http://traefik.oldboyedu.com/dashboard/#/
本文作者:张龙龙
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!