The following document describes the deployment of a basic Spring API Service and MongoDB web stack on Kubernetes. Currently this example does not use replica sets for MongoDB.
Using Replication Controllers for building MongoDB
Java: JDK 1.8
Maven Build
Docker and Minikube on local
Using Minikube: build on local
minikube start
minikube stop
$ cd api-service
$ mvn package -DskipTests=True
$ cd api-service
$ docker build -t nhatthai/api-service .
$ docker push nhatthai/api-service
$ cd manifests
$ kubectl create -f mongo-pv.yml
$ kubectl get pv
$ cd manifests
$ kubectl create -f mongo-pvc.yml
$ kubectl get pvc
$ cd manifests
$ kubectl create -f mongo-controller.yml
$ cd manifests
$ kubectl create -f mongo-service.yml
$ cd manifests
$ kubectl create -f api-deploy.yml
$ cd manifests
$ kubectl create -f api-service.yml
$ kubectl describe services
$ kubectl describe replicationcontrollers/mongo-controller
$ kubectl exec -it mongo-controller-vbqf4 -c mongo bash
$ minikube addons enable ingress
$ cd manifests
$ kubectl create -f ingress.yml
$ minikube ip
192.168.99.100
192.168.99.100 mysite.com
Check config MongoDB in api-service/src/main/resources/application.properties
We can create API Service Replication Controller instead of a API Service Deployment. Please checkout Git branch: replication-api-service
$ cd manifests
$ kubectl create -f api-controller.yml
POST http://mysite.com/student
{
"id": "1",
"name": "NhatThai",
"description": "Programmer",
"courses": [{
"id": "1",
"name": "Minikube on local",
"description": "Kubenetes",
"steps": [1]
}]
}
Running a MEAN stack on Google Cloud Platform with Kubernetes