Deploy Golang & Mongo on Kubernetes (Minikube)
At this time i will make a tutorial how to deploy simple go application with minikube, before going further you can visit my old article
- about kubernetes on : :https://wahyu-ehs.medium.com/kubernetes-k8s-simple-introduction-6f01746a1398.
- About docker on :
https://wahyu-ehs.medium.com/golang-and-mongodb-in-docker-cab7773c04ce.
At firs we need a simple go application and i have already made it, and can be downloaded from : https://github.com/wahyueko22/golang-app/tree/master/go-mongo
On the repo i created many configuration file for deploying application and mongoDB
About what is deployment, service, pv (kubernetes volume), pvc (kubernetes volume claim) please refer to kubernetes doc : https://kubernetes.io/docs/concepts/storage/persistent-volumes/
Required software for deploying go app with minikube :
- Install virtual box to start minikube
- Install minikube
- Install kubectl
- Install docker
- Create account for docker hub
- Make sure those software are running well
Steps to deploy go app with kubernates :
- Install mongo DB in kubernates
Download file with mongo prefix from https://github.com/wahyueko22/golang-app/tree/master/go-mongo/kubernetes
Run below command sequantly:
- kubectl apply -f kubernetes/mongo-pv.yaml
- kubectl apply -f kubernetes/mongo-pvc.yaml
- kubectl apply -f kubernetes/mongo-deployment.yaml
- kubectl apply -f kubernetes/mongo-service.yaml
The message should be created, not unchanged, because of i have already deployed those file so that the message is unchanged.
To see / check the service we run : minikube service service-name for example
minikube service mongodb
And base the picture we got link : http://192.168.99.100:32343
Create data according above picture, so that the json can be consumed by application.
{
"name" : "Wick",
"grade" : "5"
}
The sample code will query based on name, where the name is Wick.
2. Application deployment :
a. Create empty repo on docker hub
For example wahyuehs7/go-mongo
b. Create image
docker build -t wahyuehs7/go-mongo:1.0 .
c. Push image to docker hub
#docker push wahyuehs7/go-mongo:1.0
d. Run below command sequantly:
- kubectl apply -f kubernetes/app-deployment.yaml
- kubectl apply -f kubernetes/mongo-service.yaml
To test app service, issues command :
minikube service goapp-srv
sources :
https://github.com/wahyueko22/golang-app/tree/master/go-mongo
https://kubernetes.io/docs/concepts/storage/persistent-volumes/
https://levelup.gitconnected.com/deploy-your-first-flask-mongodb-app-on-kubernetes-8f5a33fa43b4