请问http 强制转 https 应该咋写

来源:12-10 Traefik 为Kubeimooc配置TLS证书支持

weixin_慕勒0518364

2023-09-08

Traefik配置 跟教程一样, 看了其他回答,加了中间件也不行,这个是我的demo,这个demo目前是正常的,http 跟https都能访问,如果在 https 的 ingressroute 加上 中间件,访问失败

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: test02-nginx-ingress
  namespace: test
spec:
  entryPoints:
    - https
  routes:
    - match: Host(`test02.example.com`) && PathPrefix(`/`)
      kind: Rule
      services:
        - name: test02-traefik-advanced-service
          port: 80
  tls:
    secretName: test-cert
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: traefik-advanced-ingressroute
  namespace: test
spec:
  entryPoints:
    - http
  routes:
    - match: Host(`test02.example.com`) && PathPrefix(`/`)
      kind: Rule
#      middlewares:
#        - name: redirect-to-https # 选择 中间件
      services:
        - name: test02-traefik-advanced-service
          port: 80
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: redirect-to-https
spec:
  redirectScheme:
    scheme: https
    permanent: false # 永久重定向,如果需要临时重定向,可以将其设置为false
---
apiVersion: v1
kind: Service
metadata:
  name: test02-traefik-advanced-service
  namespace: test
spec:
  type: NodePort
  selector:
    app: test02-traefik-advanced-pod
  ports:
    - name: http
      port: 80
#      nodePort: 30083

---
apiVersion: v1
kind: Pod
metadata:
  name: test02-traefik-advanced-pod
  namespace: test
  labels:
    app: test02-traefik-advanced-pod
spec:
  containers:
    - name: nginx
      image: nginx:1.17.1
      ports:
        - name: nginx-port
          containerPort: 80



写回答

1回答

暮闲

2023-09-09

同学你好 你的中间件是作用在http还是https? 然后重定向设置为true有试过吗?

0
6
weixin_慕勒0518364
回复
暮闲
解决了,是我个人漏了 加namespace
2023-09-12
共6条回复

Kubernetes系统精讲 Go语言实战K8S集群可视化

核心知识+高阶应用+原理剖析+二次开发 全方位打通K8S生产实践

399 学习 · 265 问题

查看课程