This repo consists of a simple go web application. It also has a helm chart that deploys it to a kubernetes cluster along with a config map. The objective of the repository is to understand how to use configmaps along with kubernetes apps
- Docker
- minikube
- kubernetes
- helm3
- go
- Start minikube
minikube start
- Run the following command to be able to build the docker image in the minikube docker env
eval $(minikube docker-env)
- Build the docker image in the same terminal where the above command was executed
docker build -t gok8 . - Install the application using helm
The syntax for the following command is
helm install <release-name> <chart-location>helm install v1 ./go-helm
-
Run
kubectl get podsto check the running pods. The output should be something likekubectl get pods NAME READY STATUS RESTARTS AGE go-web-app-54b544476d-mgktm 1/1 Running 0 5s go-web-app-54b544476d-vcvjj 1/1 Running 0 5s
-
Since the app exposes 2 rest endpoints namely
/and/configone can access it by runningminikube service go-web-service
where
go-web-serviceis the name of the kubernetes service we deployed The above command establishes a ssh tunnel with our kubernetes app and opens a browserThe output of the above command is something like
minikube service go-web-service |-----------|----------------|-------------|---------------------------| | NAMESPACE | NAME | TARGET PORT | URL | |-----------|----------------|-------------|---------------------------| | default | go-web-service | http/80 | http://192.168.49.2:32029 | |-----------|----------------|-------------|---------------------------| 🏃 Starting tunnel for service go-web-service. |-----------|----------------|-------------|------------------------| | NAMESPACE | NAME | TARGET PORT | URL | |-----------|----------------|-------------|------------------------| | default | go-web-service | | http://127.0.0.1:57922 | |-----------|----------------|-------------|------------------------| 🎉 Opening service default/go-web-service in default browser... ❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
-
One can now navigate to
http://127.0.0.1:57922/configto view the config map that was loaded Note that the port number will be different every time
The deployment.yaml has an annotation that is tied to the sha256sum of the client_config.json file.
This is so that the pods restart automatically if there is any change to the client_config.json file
template:
metadata:
labels:
name: go-web-app
annotations:
checksum/config: {{ .Files.Get "client_config.json" | sha256sum }}So now modify the client_config.json and upgrade the release by running
helm upgrade v1 ./go-helmImmediately run kubectl get pods and you should see that the old pods are being terminated and new pods get created due to change in config map
kubectl get pods
NAME READY STATUS RESTARTS AGE
go-web-app-54b544476d-mgktm 0/1 Terminating 0 12m
go-web-app-54b544476d-vcvjj 0/1 Terminating 0 12m
go-web-app-696994cfc4-76lm5 1/1 Running 0 6s
go-web-app-696994cfc4-pzp97 1/1 Running 0 5sVerify the updated configs by again navigating to the /config end point of the app
To clean up the installation run the following helm command
helm delete <release-name>In this case it is
helm delete v1