Comments (9)
你问的是 Traefik Ingress 的问题吗?如果是的话,可以添加一个 Traefik 的 middlewares 中间件,跟路由规则进行关联,当访问对应路由规则时进行转发,示例如下:
1、创建跳转 HTTPS 的 middlewares 中间件
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: https-redirectscheme
spec:
redirectScheme:
scheme: https
2、配置基于 HTTP 的路由规则并引用该 middlewares 中间件
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: test-route
spec:
entryPoints:
- web
routes:
- match: Host(`www.mydlq.club`)
kind: Rule
services:
- name: test-service
port: 80
middlewares:
- name: https-redirectscheme ##指定使用跳转到 https 的中间件
可以参考 traefik 官方文档:https://docs.traefik.io/middlewares/redirectscheme/
如果说的不是 traefik,请写出你的详细问题,谢谢。
from blog-example.
不好意思,刚才评论发现插入yaml格式显示不对,删除了重新回复还是显示异常
按你的操作,添加了websecure,未解决
from blog-example.
from blog-example.
[root@k8s-master1 traefik2.2]# cat traefik-dashboard-route.yaml
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: traefik-dashboard-route
spec:
entryPoints:
- web,websecure
routes: - match: Host(
traefik.linux.com
)
kind: Rule
services:- name: traefik
port: 8080
middlewares: - name: https-redirectscheme
- name: regex-stripprefix-middleware
使用http://traefik.linux.com/可以自动跳转https(提示404),直接https://traefik.linux.com/访问也提示404
- name: traefik
from blog-example.
不做自动跳转访问http://traefik.linux.com可以正常访问(http://traefik.linux.com/dashboard/#/),会不会是由于/dashboard/#/ 路径问题?traefik 进行路由规则进行流量转发时,也会带上这个前缀作为相对路径发送到后端服务中,而对后端服务来说,一般都是以 “/” 根路径作为相对路径的
from blog-example.
尝试了下,我这里确实可行,如下:
1、创建跳转 HTTPS 的 middlewares 中间件
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: https-redirectscheme
spec:
redirectScheme:
scheme: https
2、创建基于 HTTP 的路由规则
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: traefik-dashboard-route-http
namespace: kube-system
spec:
entryPoints:
- web ## 指定进入端点为 HTTP 端点
routes:
- kind: Rule
match: Host(`traefik.mydlq.club`)
middlewares:
- name: https-redirectscheme ## 指定 middlewares
services:
- name: traefik
port: 8080
3、创建基于 HTTPS 的路由规则
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: traefik-dashboard-route-https
namespace: kube-system
spec:
entryPoints:
- websecure ## 指定进入端点为 HTTPS 端点
routes:
- kind: Rule
match: Host(`traefik.mydlq.club`)
services:
- name: traefik
port: 8080
tls:
secretName: cloud-mydlq-tls ## 必须要指定证书,否则会出现 404
如果你不指定证书,会导致访问 https 时候出现 404.
from blog-example.
大佬你好,我想创建一个全局转发,即所有域名的http访问均重定向到对应的https,而不限于上面的traefik ui service,我应该怎么操作呢
from blog-example.
大佬你好,我想创建一个分区转发,即所有域名的http访问均重定向到对应的https,而不是上方上面的traefik ui服务,我应该怎么操作呢
其实不同的 Namespace 之间的 middlewares 中间件是可用相互调用的,只需要指定对应的 namespace 和 资源类型。
例如这里有两个 namespace 分别为 kube-system
和 mydlqcloud
,现在配置 mydlqcloud
空间下的 IngressRoute
使用 kube-system
空间下的 middlewares
中间件,对象如下:
1、kube-system 空间下的 https 中间件
创建一个重定向到 https 的 middlewares 中间件
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: https-redirectscheme
namespace: kube-system
spec:
redirectScheme:
scheme: https
2、mydlqcloud 空间下的路由规则
这里引用 kube-system 空间下的重定向 middlewares 中间件:
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: jenkins-route
namespace: mydlqcloud
spec:
entryPoints:
- web
routes:
- kind: Rule
match: Host(`jenkins.mydlq.club`)
middlewares:
- name: kube-system-https-redirectscheme@kubernetescrd ## 是用 kube-system 下的中间件
services:
- name: jenkins
port: 8080
按照这样配置就可以引用其它命名空间下的中间件了,一个 middlewares 中间件可以被多个路由规则引用,这样设置全部 namespace 的路由规则都是用 kube-system-https-redirectscheme@kubernetescrd
就相当于全局都是用该中间件了。
这里说一下引入其它 middlewares 中间件的规则是:{namespace名称}
-{middlewares名称}
@{资源类型,一般为kubernetescrd}
from blog-example.
谢谢UP主,可以了。我未创建“3、创建基于 HTTPS 的路由规则”这个路由规则导致的。非常感谢,三连~star
from blog-example.
Related Issues (15)
- &特殊符号问题 HOT 2
- springcloud-kubernetes-feign-demo使用问题 HOT 2
- 运行springcloud-kubernetes-discovery-demo报错 HOT 3
- 用ttrss订阅贵博rss失败 HOT 1
- 博客相关的问题 HOT 3
- 搭建prometheus的时候,一直提示“CrashLoopBackOff” HOT 7
- 按照这个部署文件部署treafikv2,报错 HOT 1
- kafka logs 不能产生 mq 消息 HOT 3
- 是否能升级到ES7 HOT 1
- 按你的文件部署,为什么node上的80和443端口不是open状态 HOT 4
- 请教大神,你这个数据怎么来的 HOT 2
- 【请教】部署traefik后https访问返回403 HOT 4
- kubernetes-dashboard2.1.0-deploy errers with kubernetes v1.19.7 HOT 1
- trafik2.4按照 部署后出现问题 HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog-example.