Tuesday, 22 February 2022

Blue/Green Deployment in kubernetes

 

Blue/Green Deployment

Blue/green deployment is a continuous deployment process that reduces downtime and risk by having two identical production environments, called blue and green. 

we will start by creating a Two Deployment Manifests

vi DemoApp001.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy2
  labels:
    app: app-v1
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app-v1
  template:
    metadata:
      labels:
        app: app-v1
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: beta.kubernetes.io/arch
                operator: In
                values:
                - amd64
                - arm64
      containers:
      - name: deploy-images
        image: kellyamaploy-images:v1
        ports:
        - containerPort: 8080



vi DemoApp002.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy2
  labels:
    app: app-v2
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app-v2
  template:
    metadata:
      labels:
        app: app-v2
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: beta.kubernetes.io/arch
                operator: In
                values:
                - amd64
                - arm64
      containers:
      - name: deploy-images
        image: kellyamaploy-images:v1
        ports:
        - containerPort: 8080


Now we will apply the 2 Deployment Manifests

$ kubectl apply -f DemoApp001.yml

$ kubectl apply -f DemoApp002.yml

This will create deployments app-v1 and app-v2


Then create the Service Manifest to point to app-v1

vi ServiceApp02.yml

apiVersion: v1
kind: Service
metadata:
  name: svc2
  labels:
    app: app-v1
spec:
  ports:
  - port: 8080
    nodePort: 32600
    protocol: TCP
  selector:
    app: app-v1
  type: NodePort




copy the public cluster ip and with the port being expose in the SG(32600) and paste in the browse . You will see the App in Blue bg




Now modify the Service Manifest flip the and change the app-v1 to app-v2 and apply the below 
vi ServiceApp02.yml

apiVersion: v1
kind: Service
metadata:
  name: svc2
  labels:
    app: app-v2
spec:
  ports:
  - port: 8080
    nodePort: 32600
    protocol: TCP
  selector:
    app: app-v2
  type: NodePort



kubectl apply -f ServiceApp02.yml



Now Go Back to the Browser and refresh your screen. You should see the Green App






No comments:

Post a Comment

How to upgrade Maven

  java.lang.IllegalStateException I had installed maven in my ubuntu using command  apt install maven This installed maven in path /usr/shar...