k8s蓝绿

实现原理: 通过一个service选择标签版本号实现蓝绿不同版本的切换并结合ingress暴露服务。

一、1.0版(蓝)

blue.yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: web-1.0
spec:
  replicas: 3
  #selector:
  #  matchLabels:
  #    run: web-1.0
  template:
    metadata:
      labels:
        name: web
        version: "1.0"
    spec:
      containers:
        - name: web-1.0
          image: 192.168.20.17/www/www:1.0
          imagePullPolicy: IfNotPresent
          name: http
          ports:
          - containerPort: 80

  

 

二、2.0版(绿)

green.yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: web-2.0
spec:
  replicas: 3
  template:
    metadata:
      labels:
        name: web
        version: "2.0"
    spec:
      containers:
        - name: web
          image: 192.168.20.17/www/www:2.0
          imagePullPolicy: IfNotPresent
          name: http
          ports:
          - containerPort: 80

 

 

三、service配置(标签选择器)

service.yaml
apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: default
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    name: web
    version: "2.0"

 

 

四、rahcer为服务配置代理 

posted @ 2019-11-14 14:31  大川哥  阅读(327)  评论(0编辑  收藏  举报