Linkerd 企业身份授权与证书轮换

验证:未记录
适用版本
未记录
验证范围
尚未登记验证记录。
本文缩写(英文全称与中文含义)
缩写 英文全称/名称 中文含义
ACME Automatic Certificate Management Environment 自动化证书管理协议
API Application Programming Interface 应用程序编程接口
CA Certificate Authority 证书颁发机构
CLI Command-Line Interface 命令行接口
CNI Container Network Interface 容器网络接口
CPU Central Processing Unit 中央处理器
CRD Custom Resource Definition Kubernetes 自定义资源定义
ECDSA Elliptic Curve Digital Signature Algorithm 椭圆曲线数字签名算法
HA High Availability 高可用
HSM Hardware Security Module 硬件安全模块
mTLS Mutual Transport Layer Security 双向 TLS,通信双方都验证证书
PDB Pod Disruption Budget Pod 中断预算,约束自愿驱逐
PKI Public Key Infrastructure 公钥基础设施
SA Service Account 服务账号,供程序或工作负载使用的身份
URL Uniform Resource Locator 统一资源定位符,通常指访问地址

场景:为订单内部服务提供 mTLS 和基于 ServiceAccount 的准入,重点演练证书自动轮换与授权拒绝。前置:基线、独立 orders-linkerd 预生产业务、企业 PKI、cert-manager;与 Istio 不注入同一 Pod。

发行版与证书先决条件#

Linkerd 社区当前公开安装说明使用 edge;企业必须选择有维护承诺且已认证的固定发行版(供应商稳定版,或组织自己验证维护的固定 edge),不能把 latest edge 当生产稳定渠道。安装说明

根私钥留在 PKI/HSM。由企业 CA/cert-manager 为 Linkerd identity 签发符合该发行版要求的 ECDSA CA issuer,linkerd/linkerd-identity-issuer Secret 包含 tls.crt/tls.key/ca.crt;证书具备 CA/签名用途并与 trust anchor 相连。公有 ACME 网站证书不能代替 mesh CA。

PKI 的 issuer Secret 由 cert-manager 自动轮换,根信任 bundle 单独管理。以下示例使用已有受限 ClusterIssuer enterprise-mesh-ca,保存 linkerd-issuer.yaml:

apiVersion: cert-manager.io/v1
kind: Certificate
metadata: {name: linkerd-identity-issuer, namespace: linkerd}
spec:
  secretName: linkerd-identity-issuer
  isCA: true
  commonName: identity.linkerd.cluster.local
  duration: 48h
  renewBefore: 25h
  privateKey:
    algorithm: ECDSA
    size: 256
    rotationPolicy: Always
  usages: [cert sign, crl sign, server auth, client auth]
  issuerRef: {name: enterprise-mesh-ca, kind: ClusterIssuer}

企业 CA 必须允许该用途/有效期并满足 Linkerd 链要求;先核验证书再安装。参考 证书轮换。

Hands-on:HA 控制面与 CNI#

先下载 linkerd-values.yaml,与发行方自带 values-ha.yaml 合并。设置发行方提供的 Chart repository URL、CRD/CNI/control-plane 版本和匹配 CLI;三种 Chart 的版本号不一定相同。trust-anchors.pem 只有公开 CA bundle,无私钥。

export LINKERD_REPO='REPLACE_APPROVED_HELM_REPOSITORY_URL'
export CRD_VERSION='REPLACE_CRD_CHART_VERSION'
export CNI_VERSION='REPLACE_CNI_CHART_VERSION'
export CONTROL_VERSION='REPLACE_CONTROL_PLANE_CHART_VERSION'
helm repo add enterprise-linkerd "$LINKERD_REPO"
helm repo update
kubectl create namespace linkerd --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f linkerd-issuer.yaml
kubectl -n linkerd wait --for=condition=Ready certificate/linkerd-identity-issuer --timeout=5m
linkerd check --pre
helm upgrade --install linkerd-crds enterprise-linkerd/linkerd-crds -n linkerd --version "$CRD_VERSION"
helm upgrade --install linkerd-cni enterprise-linkerd/linkerd2-cni -n linkerd-cni --create-namespace --version "$CNI_VERSION" --wait
helm pull enterprise-linkerd/linkerd-control-plane --version "$CONTROL_VERSION" --untar --untardir ./vendor
helm upgrade --install linkerd-control-plane enterprise-linkerd/linkerd-control-plane -n linkerd --version "$CONTROL_VERSION" -f vendor/linkerd-control-plane/values-ha.yaml -f linkerd-values.yaml --set identity.issuer.scheme=kubernetes.io/tls --set-file identityTrustAnchorsPEM=trust-anchors.pem --wait --timeout 10m
linkerd check

配套 values 明确三副本、组件/proxy 资源、反亲和性与 PDB;至少三台可调度节点。使用 统一渲染检查 确认发行版未忽略字段;仓库本地以 edge chart 2026.9.3 验证字段,生产仍需选择组织维护的认证发行版。CNI 用于避免给业务 initContainer 额外网络权限;不能在禁止此能力的托管模式强行安装。Helm 安装、CNI

业务授权#

给 orders-linkerd namespace 设置 linkerd.io/inject=enabled annotation,再部署真实业务 overlay,确保 worker 使用 orders-worker SA;Pod 重建后检查 proxy ready。

kubectl create namespace orders-linkerd --dry-run=client -o yaml | kubectl apply -f -
kubectl annotate namespace orders-linkerd linkerd.io/inject=enabled --overwrite
kubectl apply -k environments/staging/orders-linkerd
linkerd check --proxy --namespace orders-linkerd

保存 orders-linkerd-policy.yaml,使用所选版本实际支持的 Server API(示例 v1beta3):

apiVersion: policy.linkerd.io/v1beta3
kind: Server
metadata: {name: orders-api, namespace: orders-linkerd}
spec:
  podSelector:
    matchLabels: {app.kubernetes.io/name: orders-api}
  port: http
  proxyProtocol: HTTP/1
---
apiVersion: policy.linkerd.io/v1alpha1
kind: MeshTLSAuthentication
metadata: {name: orders-worker, namespace: orders-linkerd}
spec:
  identities: [orders-worker.orders-linkerd.serviceaccount.identity.linkerd.cluster.local]
---
apiVersion: policy.linkerd.io/v1alpha1
kind: AuthorizationPolicy
metadata: {name: orders-worker-to-api, namespace: orders-linkerd}
spec:
  targetRef: {group: policy.linkerd.io, kind: Server, name: orders-api}
  requiredAuthenticationRefs:
    - {group: policy.linkerd.io, kind: MeshTLSAuthentication, name: orders-worker}
kubectl apply --dry-run=server -f orders-linkerd-policy.yaml
kubectl apply -f orders-linkerd-policy.yaml

Server 选中的端口需要明确允许;健康检查、metrics、网关调用也要单独确认,不能把授权扩大成所有未认证客户端来“修好探针”。授权模型见 策略配置。

企业验收与恢复#

合法 worker 完成真实订单链路;错误 SA 和未注入客户端被拒绝;控制面/代理指标显示 mTLS 与授权结果。测量加入 proxy 后的 CPU/内存/p95、连接排空,以及 PostgreSQL 等 opaque port 的实际配置。

通过 cmctl renew linkerd-identity-issuer -n linkerd 在预生产触发一次轮换,确认 issuer Secret 更新、Linkerd 使用新 issuer、新旧工作负载仍可通信,证书过期告警正确。根 CA 轮换另走新旧 bundle 重叠→重启/更新信任→移除旧根的流程,不能直接替换根文件。

按官方路径先控制面再滚动应用 proxy,升级前保存证书/values/策略;失败时恢复兼容控制面/信任链与业务 Pod,不能假设 Chart rollback 会回滚 PKI。去 mesh 前先调整 Server/授权、取消注入并滚动验证,再移除控制器/CNI。

搜索文档

输入关键词,搜索所有文档。

↑ ↓ 选择 · Enter 打开 · Esc 关闭