Compare commits

...
9 Commits
Author SHA1 Message Date
jenkins 2449f5810e Update SOLUTION.md explanation document 2023-06-25 22:07:16 +02:00
jenkins bd5c765361 Update service selector 2023-06-25 21:04:23 +02:00
jenkins 1bc0d7402a Update matchlabels in both deployments 2023-06-25 21:01:58 +02:00
jenkins 8a7195a4c8 Add green deployment 2023-06-25 20:53:09 +02:00
jenkins f7c3ff60ab Rename blue deployment 2023-06-25 20:52:46 +02:00
jenkins c396eddc90 Add new vehicle to list 2023-06-25 20:41:01 +02:00
jenkins 48be65e46d Serve to 0.0.0.0 instead of localhost only 2023-06-25 20:38:27 +02:00
jenkins b99b9e85ee Add SOLUTION.md explanation document 2023-06-25 20:37:54 +02:00
jenkins 00839644bb Add service manifest 2023-06-25 20:34:41 +02:00
5 changed files with 63 additions and 4 deletions
+23
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.
+3 -3
View File
@@ -1,16 +1,16 @@
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: vehicles name: vehicles-blue
spec: spec:
replicas: 3 replicas: 3
selector: selector:
matchLabels: matchLabels:
app: vehicles app: vehicles-blue
template: template:
metadata: metadata:
labels: labels:
app: vehicles app: vehicles-blue
version: "1.0" version: "1.0"
spec: spec:
containers: containers:
+21
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
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
+2 -1
View File
@@ -18,6 +18,7 @@ var vehicles = []Vehicle{
{ID: "3", Model: "Fiat 500e", Maker: "Fiat"}, {ID: "3", Model: "Fiat 500e", Maker: "Fiat"},
{ID: "4", Model: "Peugeot e-208", Maker: "Peugeot"}, {ID: "4", Model: "Peugeot e-208", Maker: "Peugeot"},
{ID: "5", Model: "Volkswagen ID.4", Maker: "Volkswagen"}, {ID: "5", Model: "Volkswagen ID.4", Maker: "Volkswagen"},
{ID: "6", Model: "iX1", Maker: "BMW"},
} }
func setupRouter() *gin.Engine { func setupRouter() *gin.Engine {
@@ -31,7 +32,7 @@ func setupRouter() *gin.Engine {
func main() { func main() {
router := setupRouter() router := setupRouter()
router.Run("localhost:8080") router.Run("0.0.0.0:8080")
} }
func getHealthz(c *gin.Context) { func getHealthz(c *gin.Context) {