发布时间: 2023-11-20 文章作者: myluzh 分类名称: Kubernetes 朗读文章
apiVersion: apps/v1 kind: Deployment metadata: name: hellok8s spec: replicas: 3 selector: matchLabels: app: hellok8s version: v1 template: metadata: labels: app: hellok8s version: v1 spec: containers: - name: hellok8s image: registry.cn-hangzhou.aliyuncs.com/myluzh/hellok8s:v1 --- apiVersion: v1 kind: Service metadata: name: hellok8s spec: selector: app: hellok8s version: v1 ports: - protocol: TCP port: 80 targetPort: 80创建v2版本的Deployment和Service:
--- apiVersion: apps/v1 kind: Deployment metadata: name: hellok8s-canary spec: replicas: 3 selector: matchLabels: app: hellok8s-canary version: v2 template: metadata: labels: app: hellok8s-canary version: v2 spec: containers: - name: hellok8s-canary image: registry.cn-hangzhou.aliyuncs.com/myluzh/hellok8s:v3 --- apiVersion: v1 kind: Service metadata: name: hellok8s-canary spec: selector: app: hellok8s-canary version: v2 ports: - protocol: TCP port: 80 targetPort: 800x02 Ingress配置
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: hellok8s-ingress spec: rules: - host: my.k8s.com http: paths: - path: / pathType: Prefix backend: service: name: hellok8s port: number: 802、创建 Canary Ingress,指定 v2 版本的后端服务。接下来,你需要创建Ingress资源来配置金丝雀流量的分发。在Ingress规则中,你可以使用nginx.ingress.kubernetes.io/canary-weight注解来指定流量的权重。
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: hellok8s-ingress-caanary annotations: nginx.ingress.kubernetes.io/canary: "true" nginx.ingress.kubernetes.io/canary-weight: "10" spec: rules: - host: my.k8s.com http: paths: - path: / pathType: Prefix backend: service: name: hellok8s-canary port: number: 80在上述Ingress规则中,我们通过将10%的流量转发到名为hellok8s-canary的服务,而90%的流量转发到名hellok8s的v1服务。
标签: k8s nginx Ingress 金丝雀 灰度发布
发表评论