Kubernetes has different deployment strategies you can use to deploy your applications/services with rolling update and canary deployments among the options. Blue-green deployments is just one of many deployment strategies.
Blue-green deployments offer an effective strategy to achieve seamless updates in Kubernetes. This approach allows you to roll out new versions of your application without any downtime, minimizing the impact on your users.
Understanding Blue-Green Deployments: Blue-green deployments involve maintaining two identical production environments, known as the blue environment and the green environment. The blue environment represents the current stable version of your application, while the green environment represents the new version being deployed. The deployment process involves gradually shifting traffic from the blue environment to the green environment, ensuring a smooth transition.
To run the example I had the following tools/software installed:
I also setup a alias for kubectl using the following command:
Set-Alias -Name k -Value kubectl
Make sure minikube is up and running:
minikube start
The following describes the scenario used to try and explain a blue-green deployment:
NOTE: The deployments use a custom image that displays the environment variables, this image is used for demo purposes only.
blue-green-deployment.yaml
with the following contents, which comprises of a blue deployment, green deployment and service.apiVersion: apps/v1
kind: Deployment
metadata:
name: blue-app
labels:
app: my-app
spec:
selector:
matchLabels:
version: v1
template:
metadata:
name: my-app
labels:
version: v1
spec:
containers:
- name: my-app-container
image: matthewregis/public:dotnet-display-env-var
ports:
- containerPort: 80
env:
- name: DEPLOYMENT_EXAMPLE
value: "Blue"
replicas: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: green-app
labels:
app: my-app
spec:
selector:
matchLabels:
version: v2
template:
metadata:
name: my-app
labels:
version: v2
spec:
containers:
- name: my-app-container
image: matthewregis/public:dotnet-display-env-var
ports:
- containerPort: 80
env:
- name: DEPLOYMENT_EXAMPLE
value: "Green"
replicas: 1
---
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
version: v1 # notice this is pointing to version: v1 which is the blue deployment to start off with.
ports:
- port: 80
targetPort: 80
type: NodePort
k apply -f .\blue-green-deployment.yaml
Ctrl+C
once finished.minikube service my-app-service
version: v1
to version: v2
. In theory you would have verified that the green deployment is working as expected before proceeding.k edit service my-app-service
minikube service my-app-service
You can clear your minikube environment by deleting the created deployments and service using the following commands:
k delete service my-app-service
k delete deployment blue-app
k delete deployment green-app