运维

运维相关知识和内容

Kubernetes v1.36深度解析:服务网格深度集成与Ingress-NGINX退役应对方案

Kubernetes v1.36深度解析:服务网格深度集成与Ingress-NGINX退役应对方案

版本发布背景

2026年4月23日,Kubernetes v1.36"春归万物生"正式发布。本版本在功能层面以服务网格深度集成为主旋律,但最紧迫的运维事项是:Ingress-NGINX已于2026年3月24日正式退役。

全球约67%的K8s集群使用Ingress-NGINX(根据CNCF 2026 Survey),这意味着数百万条件群需要进行流量入口层的迁移。

一、Ingress-NGINX退役影响评估

1.1 退役时间线

2025-12-15  SIG Network宣布Ingress-NGINX将在2026年Q1退役
2026-01-20  发布最后一个功能版本 ingress-nginx v1.11.5
2026-03-24  官方宣布退役,停止安全补丁支持
2026-06-30  Docker Hub官方镜像归档(不再更新)

1.2 不升级的风险

如果继续使用已退役的Ingress-NGINX:
- ❌ 不再收到CVE安全补丁
- ❌ 不支持K8s 1.36新特性(如ServiceCIDR v1 GA)
- ❌ 社区Issue不再响应
- ❌ 依赖的nginx基础镜像将落后于安全更新

1.3 迁移选项对比

方案 适用场景 迁移复杂度 额外能力
Gateway API + Nginx GW Controller 最小改动 Gateway API标准化
Istio + Gateway API 需要服务网格 mTLS、流量治理
Cilium Ingress/Gateway 高性能需求 eBPF加速
Traefik v3 简单场景 自动证书管理
Envoy Gateway 大规模场景 高度可定制

二、迁移到Gateway API实战

2.1 安装Gateway API CRDs

# 安装Gateway API v1.2(K8s 1.36配套版本)
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.2.0/standard-install.yaml

# 验证安装
kubectl get crd | grep gateway.networking.k8s.io
# 应显示:
# gatewayclasses.gateway.networking.k8s.io
# gateways.gateway.networking.k8s.io
# httproutes.gateway.networking.k8s.io
# grpcroutes.gateway.networking.k8s.io

2.2 部署Nginx Gateway Fabric(官方替代方案)

# 安装Nginx Gateway Fabric(原Ingress-NGINX团队维护的Gateway API实现)
helm repo add nginx-stable https://helm.nginx.com/stable
helm repo update

helm install nginx-gateway nginx-stable/nginx-gateway-fabric \
    --namespace nginx-gateway \
    --create-namespace \
    --set service.type=LoadBalancer \
    --version 1.4.0

2.3 迁移示例:Ingress → HTTPRoute

原Ingress配置:

# 旧版 Ingress(即将失效)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/proxy-body-size: "50m"
    nginx.ingress.kubernetes.io/rate-limit: "100"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - api.example.com
    secretName: api-tls
  rules:
  - host: api.example.com
    http:
      paths:
      - path: /api/v1
        pathType: Prefix
        backend:
          service:
            name: api-service
            port:
              number: 8080

新版Gateway API配置:

# Gateway定义(集群级别,运维团队管理)
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: prod-gateway
  namespace: nginx-gateway
spec:
  gatewayClassName: nginx
  listeners:
  - name: https
    port: 443
    protocol: HTTPS
    hostname: "*.example.com"
    tls:
      mode: Terminate
      certificateRefs:
      - kind: Secret
        name: wildcard-tls
        namespace: nginx-gateway
  - name: http
    port: 80
    protocol: HTTP
    allowedRoutes:
      namespaces:
        from: All
---
# HTTPRoute(应用团队管理,命名空间隔离)
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: api-route
  namespace: production
spec:
  parentRefs:
  - name: prod-gateway
    namespace: nginx-gateway
    sectionName: https
  hostnames:
  - "api.example.com"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /api/v1
    filters:
    - type: URLRewrite
      urlRewrite:
        path:
          type: ReplacePrefixMatch
          replacePrefixMatch: /
    - type: RequestHeaderModifier
      requestHeaderModifier:
        add:
        - name: X-Forwarded-Prefix
          value: /api/v1
    backendRefs:
    - name: api-service
      port: 8080
      weight: 100

2.4 速率限制迁移

# Gateway API 速率限制(使用BackendTLSPolicy)
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
  name: rate-limited-route
spec:
  rules:
  - filters:
    - type: ExtensionRef
      extensionRef:
        group: gateway.nginx.org
        kind: ObservabilityPolicy
        name: rate-limit-policy
    backendRefs:
    - name: api-service
      port: 8080
---
# Nginx特定限速策略
apiVersion: gateway.nginx.org/v1alpha1
kind: ObservabilityPolicy
metadata:
  name: rate-limit-policy
spec:
  rateLimit:
    requestsPerSecond: 100
    burstSize: 200
    key: "$remote_addr"

三、K8s v1.36服务网格深度集成

3.1 原生Sidecar支持(GA)

v1.36将Sidecar容器特性升级为GA,彻底解决Init容器生命周期问题:

# v1.36原生Sidecar配置(支持Istio/Cilium)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  template:
    spec:
      initContainers:
      - name: istio-proxy
        image: istio/proxyv2:1.22.0
        restartPolicy: Always  # 关键字段:声明为Sidecar
        lifecycle:
          postStart:
            exec:
              command:
              - pilot-agent
              - wait
        resources:
          limits:
            cpu: 200m
            memory: 256Mi
      containers:
      - name: app
        image: my-app:v1.0

旧版Sidecar问题修复:
- 旧版:Init容器先于业务容器启动,Sidecar就绪前业务容器已开始处理请求
- v1.36:restartPolicy: Always声明的Init容器会持续运行,并等待就绪后再启动后续容器

3.2 与Istio Ambient Mode集成

# 安装Istio Ambient Mode(无Sidecar注入)
istioctl install --set profile=ambient \
    --set "components.cni.enabled=true" \
    -y

# 为命名空间启用Ambient模式(无需重启Pod)
kubectl label namespace production istio.io/dataplane-mode=ambient

# 验证
kubectl get pods -n production -o json | \
    jq '.items[].metadata.annotations["ambient.istio.io/redirection"]'

Ambient Mode vs Sidecar模式对比:

维度 Sidecar模式 Ambient模式
资源开销 每Pod额外~50-200m CPU 集群级别共享ztunnel
部署复杂度 需要注入webhook 标签即可启用
隔离性 强(Pod级别) 节点级别
功能完整度 完整 L4完整,L7部分
适用场景 需要细粒度流量控制 大规模、低开销场景

四、其他重要新特性

4.1 ServiceCIDR v1 GA

# 动态扩展Service IP段(解决IP耗尽问题)
apiVersion: networking.k8s.io/v1
kind: ServiceCIDR
metadata:
  name: extended-cidr
spec:
  cidrs:
  - 10.96.0.0/20      # 原有CIDR
  - 10.112.0.0/20     # 新增CIDR(无需重启集群!)

4.2 Job成功策略GA

# 精确控制批处理Job的成功条件
apiVersion: batch/v1
kind: Job
spec:
  completions: 100
  parallelism: 10
  successPolicy:
    rules:
    - succeededIndexes: "0-9"   # 只要前10个任务成功即认为Job成功
      succeededCount: 10

五、升级操作指南

# 1. 升级前备份etcd
ETCDCTL_API=3 etcdctl snapshot save /backup/etcd-$(date +%Y%m%d).db

# 2. 升级控制平面(以kubeadm为例)
sudo apt-get update
sudo apt-get install -y kubeadm=1.36.0-00

# 验证升级计划
sudo kubeadm upgrade plan v1.36.0

# 执行升级
sudo kubeadm upgrade apply v1.36.0

# 3. 升级kubelet和kubectl
sudo apt-get install -y kubelet=1.36.0-00 kubectl=1.36.0-00
sudo systemctl daemon-reload
sudo systemctl restart kubelet

# 4. 升级工作节点(逐个)
kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data
# 在node-1上执行升级...
kubectl uncordon node-1

K8s v1.36的服务网格深度集成和Ingress-NGINX退役,共同推动着云原生流量架构的演进。尽早开始迁移评估,在安全补丁到期前完成迁移,是运维团队2026年上半年最重要的技术任务之一。