常见配置示例
本页汇总了最常用的配置,可按需复制和调整。
HTTPS with cert-manager
Section titled “HTTPS with cert-manager”使用 Let’s Encrypt 进行端到端 TLS 终止:
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/latest/download/cert-manager.yamlapiVersion: cert-manager.io/v1kind: ClusterIssuermetadata: name: letsencrypt-prodspec: acme: server: https://acme-v02.api.letsencrypt.org/directory privateKeySecretRef: name: letsencrypt-prod solvers: - http01: ingress: class: nginxGateway 配置 TLS:
apiVersion: gateway.networking.k8s.io/v1kind: Gatewaymetadata: name: tls-gatewayspec: gatewayClassName: nantian-gw listeners: - name: https port: 443 protocol: HTTPS tls: mode: Terminate certificateRefs: - name: gateway-tlsapiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata: name: path-routingspec: parentRefs: - name: my-gateway rules: - matches: - path: {type: PathPrefix, value: /api} backendRefs: - name: api-service port: 8080 - matches: - path: {type: PathPrefix, value: /web} backendRefs: - name: web-service port: 3000流量分割(金丝雀发布)
Section titled “流量分割(金丝雀发布)”apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata: name: canaryspec: parentRefs: - name: my-gateway rules: - backendRefs: - name: app-v1 port: 8080 weight: 90 - name: app-v2 port: 8080 weight: 10filters:- type: CORS cors: allowOrigins: ["https://app.example.com"] allowMethods: [GET, POST, PUT, DELETE] allowHeaders: [Content-Type, Authorization] allowCredentials: true maxAge: 3600更多示例请参考 英文版。