✨ TL;DR(3–4 条亮点)
Volo.Abp.Studio.Cli
)快速生成 Kubernetes 资源 & Helm Chart,将 ABP VNext 微服务部署到集群中 (ABP)DestinationRule
与 VirtualService
实现灰度发布、故障注入与重试策略,遵循 Istio 流量管理最佳实践 ️ (Istio, Istio)PeerAuthentication STRICT
)与细粒度 JWT 验证(RequestAuthentication
+ AuthorizationPolicy
),确保零信任访问控制 (Istio, Istio) 背景与动机
随着微服务规模和复杂度不断攀升,Kubernetes 原生流量路由与安全能力捉襟见肘。Istio 服务网格通过 Envoy 代理与控制平面提供透明路由、灰度发布、策略执行和遥测能力,使业务团队无需改动应用代码即可获得高可用、高可观测、零信任的微服务架构 (Istio, Istio)。
demo
profile 快速体验核心功能) (Istio)工具链
kubectl
, istioctl
, helm
dotnet tool install -g Volo.Abp.Studio.Cli
) (ABP)abp k8s generate
,自动生成包含 deployment.yaml
、service.yaml
、gateway.yaml
、virtualservice.yaml
的 Helm Chart 模板 (ABP)。docker build -t registry/myorg/usersvc:1.0.0 -f src/UserService/Dockerfile .
docker push registry/myorg/usersvc:1.0.0
将镜像推送至私有仓库后,下文部署直接引用该标签。
charts/user-service/
├─ Chart.yaml
├─ values.yaml
└─ templates/
├─ deployment.yaml
├─ service.yaml
├─ gateway.yaml
└─ virtualservice.yaml
values.yaml 示例:
image:
repository: registry/myorg/usersvc
tag: "1.0.0"
serviceAccount:
name: "user-sa"
appsettings:
Production:
ConnectionStrings:
Default: "${DB_CONNECTION_STRING}"
FeatureManagement:
BetaFeature: true
templates/deployment.yaml 关键片段:
spec:
template:
spec:
serviceAccountName: {{ .Values.serviceAccount.name }}
containers:
- name: user-svc
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Production"
volumeMounts: …
通过 Helm 模板渲染多环境动态注入 (ABP)。
istioctl install --set profile=demo -y
kubectl create namespace prod
创建 ServiceAccount 与 RBAC
kubectl create serviceaccount user-sa -n prod
kubectl create clusterrolebinding user-sa-binding \
--clusterrole=cluster-admin \
--serviceaccount=prod:user-sa
定义 Gateway(边缘流量入口)
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: user-gateway
namespace: prod
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "user.example.com"
此 Gateway 用于接收外部流量并交给后续 VirtualService
处理 (Istio)。
kubectl label namespace prod istio-injection=enabled
kubectl rollout restart deployment user-svc -n prod
标记后重启 Deployment,即可自动挂载 Envoy Sidecar,实现透明代理与度量采集 (Istio, Istio)。
DestinationRule
与熔断策略 ⚙️apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: user-svc
namespace: prod
spec:
host: user-svc.prod.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: LEAST_REQUEST
connectionPool:
http:
http1MaxPendingRequests: 50
maxRequestsPerConnection: 10
outlierDetection:
consecutiveErrors: 5
interval: 10s
baseEjectionTime: 1m
subsets:
- name: v1
labels:
version: "v1"
- name: v2
labels:
version: "v2"
单服务一份资源,定义子集、负载均衡和熔断策略 (Istio)。
VirtualService
与兜底路由 ️apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: user-svc
namespace: prod
spec:
hosts:
- "user.example.com"
gateways:
- user-gateway
http:
- name: canary-route
match:
- uri:
prefix: "/api/user"
route:
- destination:
host: user-svc.prod.svc.cluster.local
subset: v1
weight: 80
- destination:
host: user-svc.prod.svc.cluster.local
subset: v2
weight: 20
fault:
delay:
percentage:
value: 10
fixedDelay: 5s
retries:
attempts: 3
perTryTimeout: 2s
- name: default-route
route:
- destination:
host: user-svc.prod.svc.cluster.local
subset: v1
weight: 100
首条路由实现 80:20 灰度、10% 故障注入与 3 次重试,第二条兜底避免 503 (Istio, Istio)。
helm upgrade user-svc charts/user-service \
-n prod \
--set image.tag=2.0.0,service.version=v2
手动或借助 Flagger 等工具逐步调整流量权重 (ABP)。
PeerAuthentication STRICT
) istioctl install --set meshConfig.enableAutoMtls=true -y
或:
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: istio-system
spec:
mtls:
mode: STRICT
强制服务间双向 TLS,加固底层通信 (Istio)。
RequestAuthentication
) & 细粒度授权 (AuthorizationPolicy
) ️apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: user-jwt
namespace: prod
spec:
selector:
matchLabels:
app: user-svc
jwtRules:
- issuer: "https://issuer.example.com"
jwksUri: "https://issuer.example.com/.well-known/jwks.json"
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: user-svc-policy
namespace: prod
spec:
selector:
matchLabels:
app: user-svc
action: ALLOW
rules:
- from:
- source:
requestPrincipals: ["*"]
- when:
- key: request.auth.claims[role]
values: ["admin","service"]
前者校验 JWT,后者基于服务账号或 Claims 做权限控制 (Istio, Istio)。
livenessProbe:
httpGet:
path: /health/liveness
port: 80
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /health/readiness
port: 80
initialDelaySeconds: 5
periodSeconds: 5
确保容器就绪后才接流量,失败时自动重启 (ABP)。
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.17/samples/addons/prometheus.yaml
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.17/samples/addons/grafana.yaml
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.17/samples/addons/jaeger.yaml
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.17/samples/addons/kiali.yaml
istio_requests_total
、istio_request_duration_milliseconds
等核心指标快速访问面板:
istioctl dashboard prometheus
istioctl dashboard grafana
istioctl dashboard jaeger
istioctl dashboard kiali
# .github/workflows/ci-cd.yml
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Lint Helm Chart
run: helm lint charts/user-service
- name: Dry-run Deploy
run: helm upgrade --install user-svc charts/user-service \
-n prod --set image.tag=${{ github.sha }} --dry-run --debug
- name: Build & Push Image
run: |
docker build -t ${{ secrets.REGISTRY }}/usersvc:${{ github.sha }} .
echo ${{ secrets.REGISTRY_PASSWORD }} | docker login ${{ secrets.REGISTRY }} -u ${{ secrets.REGISTRY_USER }} --password-stdin
docker push ${{ secrets.REGISTRY }}/usersvc:${{ github.sha }}
- name: Deploy Release
run: helm upgrade --install user-svc charts/user-service \
-n prod --set image.tag=${{ github.sha }}
- name: Wait for Rollout
run: kubectl rollout status deployment/user-svc -n prod
- name: Rollback on Failure
if: failure()
run: helm rollback user-svc 0 -n prod
helm lint
与 --dry-run --debug
预先验证配置 ✔️ (Istio)kubectl rollout status
监控部署完成 ✔️ (Istio)helm rollback
回滚稳定版本 ✔️ (ABP)groups:
- name: istio-mesh
rules:
- alert: IstioHighErrorRate
expr: |
sum(rate(istio_requests_total{reporter="destination",response_code=~"5.*"}[5m]))
/
sum(rate(istio_requests_total{reporter="destination"}[5m])) > 0.05
for: 10m
labels:
severity: page
annotations:
summary: "High error rate for {{ $labels.destination_workload }}"
description: "Error rate >5% for over 10 minutes in {{ $labels.destination_workload }}."
Prometheus 结合 Alertmanager 通知运维,快速响应故障 (Istio)。