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

推荐订阅源

GbyAI
GbyAI
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
腾讯CDC
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
量子位
博客园 - 聂微东
Jina AI
Jina AI
小众软件
小众软件
The Cloudflare Blog
有赞技术团队
有赞技术团队
V
V2EX
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
B
Blog
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
宝玉的分享
宝玉的分享
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
N
Netflix TechBlog - Medium
I
InfoQ
J
Java Code Geeks
S
SegmentFault 最新的问题
V
Visual Studio Blog
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
D
DataBreaches.Net
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog RSS Feed
S
Schneier on Security
Webroot Blog
Webroot Blog
P
Proofpoint News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
Project Zero
Project Zero
Scott Helme
Scott Helme
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
T
The Exploit Database - CXSecurity.com
D
Darknet – Hacking Tools, Hacker News & Cyber Security

打工人日志

2026-05-28 打工人日报 2026-05-27 打工人日报 2026-05-26 打工人日报 2026-05-25 打工人日报 2026-05-24 打工人日报 2026-05-23 打工人日报 2026-05-22 打工人日报 2026-05-21 打工人日报 2026-05-20 打工人日报 2026-05-19 打工人日报 2026-05-18 打工人日报 2026-05-17 打工人日报 2026-05-16 打工人日报 2026-05-15 打工人日报 2026-05-14 打工人日报 2026-05-13 打工人日报 2026-05-12 打工人日报 2026-05-11 打工人日报 2026-05-10 打工人日报 2026-05-09 打工人日报 2026-05-08 打工人日报 2026-05-07 打工人日报 2026-05-06 打工人日报 2026-05-05 打工人日报 2026-05-04 打工人日报 2026-05-03 打工人日报 2026-05-02 打工人日报 2026-05-01 打工人日报 2026-04-30 打工人日报 2026-04-29 打工人日报 2026-04-28 打工人日报 2026-04-27 打工人日报 2026-04-26 打工人日报 2026-04-25 打工人日报 2026-04-24 打工人日报 2026-04-23 打工人日报 2026-04-22 打工人日报 2026-04-21 打工人日报 2026-04-20 打工人日报 2026-04-19 打工人日报 2026-04-18 打工人日报 2026-04-17 打工人日报 2026-04-16 打工人日报 2026-04-15 打工人日报 2026-04-14 打工人日报 2026-04-13 打工人日报 2026-04-12 打工人日报 2026-04-11 打工人日报 2026-04-10 打工人日报 2026-04-09 打工人日报 2026-04-08 打工人日报 2026-04-07 打工人日报 2026-04-06 打工人日报 2026-04-05 打工人日报 2026-04-04 打工人日报 2026-04-03 打工人日报 2026-04-02 打工人日报 2026-04-01 打工人日报 2026-03-31 打工人日报 2026-03-30 打工人日报 2026-03-29 打工人日报 2026-03-28 打工人日报 2026-03-27 打工人日报 2026-03-26 打工人日报 2026-03-25 打工人日报 2026-03-24 打工人日报 2026-03-23 打工人日报 2026-03-22 打工人日报 2026-03-21 打工人日报 2026-03-20 打工人日报 2026-03-19 打工人日报 2026-03-18 打工人日报 2026-03-17 打工人日报 2026-03-16 打工人日报 2026-03-15 打工人日报 2026-03-14 打工人日报 2026-03-13 打工人日报 2026-03-12 打工人日报 2026-03-11 打工人日报 2026-03-10 打工人日报 2026-03-09 打工人日报 2026-03-08 打工人日报 2026-03-07 打工人日报 2026-03-06 打工人日报 2026-03-05 打工人日报 2026-03-04 打工人日报 2026-03-03 打工人日报 2026-03-02 打工人日报 2026-03-01 打工人日报 2026-02-28 打工人日报 2026-02-27 打工人日报 2026-02-26 打工人日报 2026-02-25 打工人日报 2026-02-24 打工人日报 2026-02-23 打工人日报 2026-02-22 打工人日报 2026-02-21 打工人日报 2026-02-20 打工人日报 2026-02-19 打工人日报 2026-02-18 打工人日报
Kubernetes — SSL 证书自动更新
2025-09-29 · via 打工人日志

介绍

提供一个在 Kubernetes 中使用 cert-manager + Cloudflare 自动签发并自动更新 Let’s Encrypt 证书的完整思路与示例(DNS-01 验证),方便你在集群内自动化 TLS 证书更新。

前置条件

  • Kubernetes 集群:可正常访问外网。不做网络环境配置的教程,具体可以去看其他文章
  • Cloudflare 账号:已将你的域名托管到 Cloudflare。使用 Cloudflare 做 dns-01 挑战
  • kubectl:已连接到集群。最基本的条件,保证k8s能正常访问
  • helm:推荐用 Helm 安装 cert-manager。使用helm安装,方便干净

安装

官方推荐用 Helm,这里我使用 1.18.2 的版本,在我这个时间点这个版本还是比较新的

安装 cert-manager

1# 安装 cert-manager CRDs
2kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.18.2/cert-manager.crds.yaml
1## Add the Jetstack Helm repository
2helm repo add jetstack https://charts.jetstack.io --force-update
1## Install the cert-manager helm chart
2helm install cert-manager --namespace cert-manager --version v1.18.2 jetstack/cert-manager

验证:

1kubectl get pods -n cert-manager

准备 Cloudflare API Token

  1. 登陆 Cloudflare Dashboard
  • My Profile → API Tokens → Create Token。
  1. 模板选:Edit zone DNS

  2. 权限:

  • Zone → DNS → Edit
  • Zone → Zone → Read
  1. Zone Resources: 选择需要签发证书的域名。

  2. 保存 token,例如:CF_API_TOKEN=xxxxxxxxxx

创建 Secret 存放 Token

1kubectl create secret generic cloudflare-api-token-secret \
2  --from-literal=api-token=CF_API_TOKEN \
3  -n cert-manager

配置 ClusterIssuer

cluster-issuer.yaml

 1apiVersion: cert-manager.io/v1
 2kind: ClusterIssuer
 3metadata:
 4  name: letsencrypt-dns
 5spec:
 6  acme:
 7    # 生产环境地址
 8    server: https://acme-v02.api.letsencrypt.org/directory
 9    email: your-email@example.com        # 接收过期提醒
10    privateKeySecretRef:
11      name: letsencrypt-dns-key
12    solvers:
13    - dns01:
14        cloudflare:
15          email: your-email@example.com  # 或留空(若使用 API token 可不填 email)
16          apiTokenSecretRef:
17            name: cloudflare-api-token-secret
18            key: api-token

部署yaml

1kubectl apply -f cluster-issuer.yaml

申请证书

在需要证书的命名空间下创建 Certificate 对象,例如 Nginx Ingress 的域名 example.com
certificate.yaml

 1apiVersion: cert-manager.io/v1
 2kind: Certificate
 3metadata:
 4  name: example-com
 5  namespace: default
 6spec:
 7  secretName: example-com-tls        # 生成的 secret 名称
 8  issuerRef:
 9    name: letsencrypt-dns
10    kind: ClusterIssuer
11  commonName: example.com
12  dnsNames:
13  - example.com
14  - "*.example.com"                   # 可选:通配符

部署yaml

1kubectl apply -f certificate.yaml

在 Ingress 中引用

 1apiVersion: networking.k8s.io/v1
 2kind: Ingress
 3metadata:
 4  name: example-ingress
 5  annotations:
 6    kubernetes.io/ingress.class: nginx
 7    cert-manager.io/cluster-issuer: letsencrypt-dns # 配置证书自动生成
 8spec:
 9  tls:
10  - hosts:
11    - example.com
12    secretName: example-com-tls #修改成自己要使用的tls名称会自动生成
13  rules:
14  - host: example.com
15    http:
16      paths:
17      - path: /
18        pathType: Prefix
19        backend:
20          service:
21            name: web
22            port:
23              number: 80

cert-manager 会在证书到期前约 30 天 自动续期。

查看状态

1kubectl describe certificate example-com -n default

复用证书

因为证书只能部署在制定的 namespace下,因此我写了一个脚本,把default命名空间下的 example-com-tls Secret复制到 argocdlonghorn-systemcattle-system 等多个命名空间。

 1#!/bin/bash
 2# 文件名:copy-example-cert.sh
 3# 作用:将 default 命名空间下的 example-com-tls Secret
 4#       复制到 argocd、longhorn-system、cattle-system
 5
 6SRC_NS="default"
 7SECRET_NAME="example-com-tls"
 8TARGET_NAMESPACES=("argocd" "longhorn-system" "cattle-system")
 9
10for ns in "${TARGET_NAMESPACES[@]}"; do
11  echo ">>> 正在复制到命名空间: $ns"
12  kubectl get secret "$SECRET_NAME" -n "$SRC_NS" -o yaml \
13    | sed "s/namespace: $SRC_NS/namespace: $ns/" \
14    | kubectl apply -f -
15done
16
17echo "✅ 复制完成"

执行

脚本会依次输出

1>>> 正在复制到命名空间: argocd
2secret/example-com-tls created
3>>> 正在复制到命名空间: longhorn-system
4secret/example-com-tls created
5>>> 正在复制到命名空间: cattle-system
6secret/example-com-tls created
7✅ 复制完成