Compare commits

...

8 Commits

5 changed files with 63 additions and 4 deletions

23
SOLUTION.md Normal file
View File

@ -0,0 +1,23 @@
# Intro
This document decribes a blue-green deployment using a simple Go web app and Minikube.
To get started, you will need to:
- Install minikube
- Execute `minikube start` to start the cluster
# Deploying the first version of our application
Using the Dockerfile a container image is built. We pushed this image to our container registry.
First, we apply the 'blue' deployment by running `kubectl apply -f deployment-blue.yaml` and `kubectl apply -f service.yaml`.
his deploys a pod with a 3 containers running v1.0 of the application. This version contains 5 vehicles in the list.
We get the service URL by running `minikube service vehicles-service --url`
Use curl to make a GET request to the `/vehicles` endpoint. We now get the list of 5 vehicles as a response.
# Updating our application
We now make a change to the application, for example by adding a new vehicle to the list. This new version is given version number 1.1. We build the container image again, now with tag 1.1.
We now apply the "green" deployment by running `kubectl apply -f deployment-green.yaml`. When the deployment is running without issues, we can update our service manifest to now point to our new version 1.1 of the application. This can be done by updating the values under `selector`. The value of `app` will now become the same as `matchLabels.app` in the `deployment-green.yaml` file, which is `vehicles-green` in this case.
After applying the updated service manifest, we can get the URL again, use curl to call the `/vehicles` endpoint. We can now see the newly added vehicle in the list.

View File

@ -1,16 +1,16 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: vehicles
name: vehicles-blue
spec:
replicas: 3
selector:
matchLabels:
app: vehicles
app: vehicles-blue
template:
metadata:
labels:
app: vehicles
app: vehicles-blue
version: "1.0"
spec:
containers:

View File

@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: vehicles-green
spec:
replicas: 3
selector:
matchLabels:
app: vehicles-green
template:
metadata:
labels:
app: vehicles-green
version: "1.1"
spec:
containers:
- name: vehicles-green
image: git.bngrs.net/jan/devops-release:1.1
ports:
- name: http
containerPort: 8080

14
kubernetes/service.yaml Normal file
View File

@ -0,0 +1,14 @@
---
apiVersion: v1
kind: Service # Type of kubernetes resource
metadata:
name: vehicles-service
spec:
type: NodePort # A port is opened on each node in your cluster via Kube proxy.
ports: # Take incoming HTTP requests on port 9090 and forward them to the targetPort of 8080
- name: http
port: 8080
targetPort: 8080
selector:
app: vehicles-blue

View File

@ -18,6 +18,7 @@ var vehicles = []Vehicle{
{ID: "3", Model: "Fiat 500e", Maker: "Fiat"},
{ID: "4", Model: "Peugeot e-208", Maker: "Peugeot"},
{ID: "5", Model: "Volkswagen ID.4", Maker: "Volkswagen"},
{ID: "6", Model: "iX1", Maker: "BMW"},
}
func setupRouter() *gin.Engine {
@ -31,7 +32,7 @@ func setupRouter() *gin.Engine {
func main() {
router := setupRouter()
router.Run("localhost:8080")
router.Run("0.0.0.0:8080")
}
func getHealthz(c *gin.Context) {