惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
博客园 - 【当耐特】
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
小众软件
小众软件
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
MyScale Blog
MyScale Blog

博客园 - Morya

不当心升级到 redis 7.4 怎么回到 valkey8 使用 cert-manager 为 traefik 自动申请和续约 https 证书 traefik学习 k8s 1.28 安装配置 knative-serving v1.15.2 + cert-manager v1.16.1 ssh端口映射玩法 golang echo group 用法的微妙注意点 使用docker最小化部署Git CI环境 使用mailpopbox构建个人独享EmailServer Influx cli cheetsheet 通过php docker快速验证简单代码 通过k8s service代理外部服务 run gitlab-runner in k8s ucloud k8s部署traefik的forward-auth 使用nginx构建限频、限速、限并发的应用保护层 macos 更改罗技k810无线键盘的映射 - Morya - 博客园 C++11 thread condition_variable mutex 综合使用 goland scope pattern 设置 Go 1.11 Module 介绍 - Morya hustOJ 添加 golang 支持
K8S配置traefik ingressroutes支持TLS
Morya · 2020-08-06 · via 博客园 - Morya

K8S配置traefik ingressroutes支持TLS

最终效果

参考traefik文档ingressroutes部分,刚读时非常令人费解。

https://docs.traefik.io/https/tls/#certificates-stores

In Traefik, certificates are grouped together in certificates stores.

Any store definition other than the default one (named default) will be ignored, and there is thefore only one globally available TLS store.

这两个描述,直接坑杀了我2天时间。

一直以为traefik的tls模型是:

ingressroutes --引用--> tlsstore --引用--> [k8s tls secret]

其实,ingressroutes里,我知道的部分,service和tls都可以直接引用k8s的标准资源。

  • service
  • tls

假设,我们有如下资源:

  • k8s tls secret
  • k8s service
    • k8s deployment

我们需要提供如下域名的https接入访问:

apiVersion: v1
data:
  tls.crt: .....
  tls.key: .....
kind: Secret
metadata:
  name: tls-abc.com
  namespace: default
type: kubernetes.io/tls

---

apiVersion: v1
data:
  tls.crt: .....
  tls.key: .....
kind: Secret
metadata:
  name: tls-def.com
  namespace: default
type: kubernetes.io/tls

deployment and service

apiVersion: v1
kind: Service
metadata:
  name: whoami
  labels:
    app: whoami
spec:
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: whoami

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: whoami
spec:
  selector:
    matchLabels:
      app: whoami
  replicas: 1
  template:
    metadata:
      labels:
        app: whoami
    spec:
      containers:
      - name: whoami
        image: containous/whoami
        ports:
        - containerPort: 80

IngressRoutes www.abc.com

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ir-www.abc.com-https  ## https 单独定义一个,和http分离部署
  namespace: default

spec:
  entryPoints:
    - websecure
  routes:
    - kind: Rule
      match: Host(`www.abc.com`) && PathPrefix(`/`)
      services:
        - kind: Service
          name: whoami
          port: 80
      tls: {}
  tls:
    secretName: tls-abc.com  ## 此处引用k8s secret
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ir-www.abc.com-http ## http 单独定义一个,和https分离部署
  namespace: default
spec:
  entryPoints:
    - web
  routes:
    - kind: Rule
      match: Host(`www.abc.com`) && PathPrefix(`/`)
      services:
        - kind: Service
          name: whoami
          port: 80

IngressRoutes www.def.com

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ir-www.def.com-https  ## https 单独定义一个,和http分离部署
  namespace: default

spec:
  entryPoints:
    - websecure
  routes:
    - kind: Rule
      match: Host(`www.def.com`) && PathPrefix(`/api`)
      services:
        - kind: Service
          name: whoami
          port: 80
      tls: {}
  tls:
    secretName: tls-def.com  ## 此处引用k8s secret
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ir-www.def.com-http ## http 单独定义一个,和https分离部署
  namespace: default
spec:
  entryPoints:
    - web
  routes:
    - kind: Rule
      match: Host(`www.def.com`) && PathPrefix(`/api`)
      services:
        - kind: Service
          name: whoami
          port: 80