me25
me25

Reputation: 557

kubernetes Blue green deployment

Kubernetes Blue-green deployment, I am patching the Kubernetes-application-service to redirect the traffic from app-v1 to app-v2(Behind the load balancer). if any connection is ongoing on during that "patching", will be disconnected? and if not !! how I can test this?

what is the best approach as per you for version deployment with the warm handover(without any connection loss) from app-v1 to app-v2?

Upvotes: 3

Views: 1131

Answers (2)

shubham singh
shubham singh

Reputation: 559

If you are trying to achieve Blue/Green in Kubernetes then my answer might help you.

Do a rolling update by setting the following configuration

  1. maxUnavailable = 0
  2. maxSurge = 100%

How? The deployment controller first scales the latest version up to 100% of the obsolete version. Once the latest version is healthy, it immediately scales the obsolete version down to 0%.

Example Code:

kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
        image: nginx:1.14.2
        ports:
          - containerPort: 80
  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 0
      type: RollingUpdate

Upvotes: 0

wpnpeiris
wpnpeiris

Reputation: 858

The question seems to be about supporting two versions at the same time. That is kind of Canary deployment, which make production traffic to gradually shifting from app-v1 to app-v2.

This could be achieved with:

  • Allow deployments to have HPA with custom metric that based on number of connections. That is, when it reaches certain number of connections scale up/down.
  • Allow two deployments at the same time, app-v1 and app-v2.
  • Allow new traffic to route on new deployment via some Ingress annotation, but still keeping access to the old version, so no existing connection be dropped.
  • Now, all the new requests will be routed to the new version. The HPA eventually, scale down pods from old version. (You can even allow deployment to have zero replicas).

Addition to your question above blue-green deployments. The blue-green deployment is about having two identical environments, where one environment active at a time, let's say blue is active on production now. Once you have a new version ready for deployment, say green, is deployed and tested separately. Finally, you switched the traffic to the green environment, when you are happy with the test result on green environment. So green become active while blue become idle or terminated later sometime. (Referred from martin fowler article).

In Kubernetes, this can be achieved with having two identical deployments. Here is a good reference.

Basically, you can have two identical deployments, assume you have current deployment my-deployment-blue is on production. Once you are ready with the new version, you can deploy it as a completely new deployment, lets say my-deployment-green, and use a separate test service to test the green environment. Finally, switch the traffic to the my-deployment-green when all test are passed.

Upvotes: 1

Related Questions