Istio 企业 mTLS、授权与灰度升级
验证:未记录
- 适用版本
- 未记录
- 验证范围
- 尚未登记验证记录。
本文缩写(英文全称与中文含义)
| 缩写 | 英文全称/名称 | 中文含义 |
|---|---|---|
| API | Application Programming Interface | 应用程序编程接口 |
| AWS | Amazon Web Services | 亚马逊云服务 |
| CA | Certificate Authority | 证书颁发机构 |
| CNI | Container Network Interface | 容器网络接口 |
| CPU | Central Processing Unit | 中央处理器 |
| CRD | Custom Resource Definition | Kubernetes 自定义资源定义 |
| DB | Database | 数据库 |
| ECS | Elastic Container Service | AWS 容器编排服务 |
| GCP | Google Cloud Platform | Google 云平台 |
| GKE | Google Kubernetes Engine | Google 托管 Kubernetes 服务 |
| HSM | Hardware Security Module | 硬件安全模块 |
| IP | Internet Protocol | 网际协议;IP 地址是网络寻址标识 |
| JWT | JSON Web Token | 一种携带声明的令牌格式 |
| mTLS | Mutual Transport Layer Security | 双向 TLS,通信双方都验证证书 |
| OSS | Open-Source Software | 开源软件 |
| PDB | Pod Disruption Budget | Pod 中断预算,约束自愿驱逐 |
| PKI | Public Key Infrastructure | 公钥基础设施 |
| SA | Service Account | 服务账号,供程序或工作负载使用的身份 |
| xDS | x Discovery Service APIs | Envoy 的一组动态发现接口,x 代表不同资源类型 |
场景:订单内部 API 只接受指定 worker 身份,升级 mesh 时先试点后推广。本篇使用 sidecar 模式,不混写 ambient/waypoint 配置。前置:基线,独立 orders-mesh 预生产副本、独立数据/队列,以及支持 Istio CNI 的集群;与 Linkerd 不注入同一 Pod。
企业身份与安装#
企业 PKI 在离线/HSM 中保存根 CA,为本集群签发中间 CA;按 Istio cacerts Secret 的 ca-cert.pem、ca-key.pem、root-cert.pem、cert-chain.pem 格式安全交付至 istio-system。根私钥不能进 Git/集群;中间 CA Secret 也要限制权限和备份。先完成 CA 轮换方案,不使用未管理的 quickstart CA 上线。外部 CA
helm repo add istio https://istio-release.storage.googleapis.com/charts
helm repo update
export ISTIO_VERSION='REPLACE_VERSION'
export REVISION='prod-canary'
helm upgrade --install istio-base istio/base -n istio-system --create-namespace --version "$ISTIO_VERSION" --wait
# 已安全交付 cacerts 后继续。CNI 避免给业务 initContainer NET_ADMIN。
helm upgrade --install istio-cni istio/cni -n istio-system --version "$ISTIO_VERSION" --wait
helm upgrade --install "istiod-$REVISION" istio/istiod -n istio-system --version "$ISTIO_VERSION" --set "revision=$REVISION" --set pilot.cni.enabled=true --set pilot.replicaCount=3 --set pilot.autoscaleMin=3 --wait --timeout 10m
istioctl analyze -A生产将这些值、资源/PDB、拓扑、proxy requests/limits、CA 配置锁进完整 values;CNI 的 hostPath/优先级与 GKE 等平台限制按安装文档处理。确认新节点在 CNI 就绪前不会跑绕过代理的应用。CNI
Hands-on:真实业务加入 mesh#
将基线业务清单以 overlay 部署到 orders-mesh,Secret、DB/队列、SA 和 NetworkPolicy 同步适配;确保 worker 的 SA 是 orders-worker。若原 API 是公网入口目标,不直接在原 namespace 启用 STRICT,先演练入口到 mesh 的连接方案。
kubectl create namespace orders-mesh --dry-run=client -o yaml | kubectl apply -f -
kubectl label namespace orders-mesh "istio.io/rev=$REVISION" --overwrite
# 部署真实业务 overlay,自动注入发生在新建 Pod 时。
kubectl apply -k environments/staging/orders-mesh
kubectl -n orders-mesh rollout status deployment/orders-api --timeout=10m
istioctl proxy-status确认 API/worker 均有健康 proxy、证书有效、xDS 同步。业务 NetworkPolicy 要允许控制面证书/xDS、监控和 mesh 通路;应用 SA/namespace 才是授权身份,不是 Pod IP。
保存 orders-mesh-policy.yaml,限制 API 8080:
apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata: {name: orders-api-mtls, namespace: orders-mesh}
spec:
selector:
matchLabels: {app.kubernetes.io/name: orders-api}
mtls: {mode: STRICT}
---
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata: {name: orders-api-callers, namespace: orders-mesh}
spec:
selector:
matchLabels: {app.kubernetes.io/name: orders-api}
action: ALLOW
rules:
- from:
- source:
principals: [cluster.local/ns/orders-mesh/sa/orders-worker]
to:
- operation: {ports: ["8080"]}kubectl apply --dry-run=server -f orders-mesh-policy.yaml
kubectl apply -f orders-mesh-policy.yaml
istioctl analyze -n orders-mesh这会拒绝未列出的入口和 metrics 抓取客户端;生产放行时列出真实网关/监控的 mesh principal,或将健康/metrics 端口分离并明确策略。mTLS 只验证工作负载身份,不代替终端用户 JWT/业务权限。认证授权
企业验收、灰度与恢复#
验收合法 worker 完成真实请求;错误 SA 即使在同 namespace 也被拒绝;未入 mesh 的调用方失败。查看 connection_security_policy=mutual_tls 等实际指标/证书状态,不能以“装了 sidecar”断言流量已加密。
在相同业务压力下测 proxy CPU/内存、p95、连接池与重试放大。支付/建单等非幂等请求禁止泛化自动重试,错误注入仅对合成账户和指定路由。重建一个 istiod Pod,已建立数据面仍服务;新 Pod/证书更新也要验收。
升级安装另一个 revision,只把试点 namespace 的 revision 标签迁到新值并滚动重建业务,验证后再扩大。故障时标签回到保留的旧 revision,再滚动重建;不能只回滚 istiod 镜像而保留不兼容 proxy。Canary 升级
移除 mesh 前先调整 STRICT/授权及调用路径,再滚动去注入,最后清理控制面;删除 CRD/CA 或 CNI 会扩大影响。根 CA 轮换采用重叠信任窗口,单独演练跨 revision 与长连接,不与 Kubernetes/CNI 升级混做。
云平台专题:AWS App Mesh 迁移与 ECS Service Connect、GCP Cloud Service Mesh。托管 GCP 网格不要重复安装本文 OSS 控制面。