- Docker or Docker alternative - Colima
- Minikube
- Helm
- kubectl
- IDE and JDK
If you want to start from the scratch without cloning this repository, then perform following steps:
- Create project using https://start.spring.io/ with name "springboot-on-minikube"
- Then add sample controller for creating rest api
- From the terminal cd into your project directory and build project using
./gradlew clean build
- Start docker on the system
- Build docker image using :
docker build -t springboot-on-minikube .
Command reference - Run the docker container:
docker run -p 8080:8080 springboot-on-minikube
and verify calling urllocalhost:8080/data
- Now stop the container service and we will create helm chart.
- Run command to create helm chart :
helm create ytkubechart
- To see helm directory structure :
tree ytkubechart
- Then do following changes in values.yaml file
image:
repository: springboot-on-minikube
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"
-
Change service to NodePort in values.yaml file
service: type: NodePort port: 8080
and comment following in deployment.yaml file
# livenessProbe: # httpGet: # path: / # port: http # readinessProbe: # httpGet: # path: / # port: http
-
Now go into terminal and start minikube using
minikube start --driver=docker
-
Enable docker env using command :
eval $(minikube docker-env)
Command Reference -
Build docker image in minikube :
docker build -t springboot-on-minikube .
-
To see images :
minikube image ls
-
Next install and deploy helm chart on cluster :
helm install mychart ytkubechart
-
Verify the configuration using commands like
kubectl get pods kubectl get service
-
To access api, run command :
minikube service mychart-ytkubechart --url
Command Reference -
Copy url returned by the command mentioned in step : 18 and call that url from browser.
-
To enable ingress on minikube run following command :
minikube addons enable ingress
Command reference 1 Ref 2 -
Verify ingress controller is running :
kubectl get pods -n ingress-nginx
-
Now do ingress configuration changes in values.yaml
service: type: ClusterIP port: 8080
ingress: enabled: true className: "" annotations: {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" hosts: - host: ytlecture.com paths: - path: / pathType: Prefix tls: []
-
Update version in Chart.yaml file
version: 0.1.2
-
Now to update our kubernetes configuration, run command in terminal :
helm upgrade mychart ytkubechart
-
Verify ingress service using :
kubectl get ingress
-
Next add entry in
/etc/hosts
file- run
sudo vi /etc/hosts
- enter password
- press
i
key on keyboard - add entry :
127.0.0.1 ytlecture.com
- press
Esc
key on keyboard - press
:wq
- run
-
verify changes using
cat /etc/hosts
-
Enable tunnel running command :
minikube tunnel
-
Then call url in browser : http://ytlecture.com/data
-
Hurray 👏 you have successfully deployed your first spring rest api on Kubernetes.
-
Stop minikube using :
minikube stop
- From the terminal cd into your project directory and build project using
./gradlew clean build
- Start docker on system
- Build docker image using :
docker build -t springboot-on-minikube .
- Run the docker container:
docker run -p 8080:8080 springboot-on-minikube
and verify calling urllocalhost:8080/data
- Now stop the container service
- start minikube using
minikube start --driver=docker
- Enable docker env using command :
eval $(minikube docker-env)
Command Reference - Build docker image in minikube :
docker build -t springboot-on-minikube .
- To see images :
minikube image ls
- To enable ingress on minikube run following command :
minikube addons enable ingress
Command reference 1 Ref 2 - Verify ingress controller is running :
kubectl get pods -n ingress-nginx
- Next install and deploy helm chart on cluster :
helm install mychart ytkubechart
- Verify ingress service using :
kubectl get ingress
- Next add entry in
/etc/hosts
file- run
sudo vi /etc/hosts
- enter password
- press
i
key on keyboard - add entry :
127.0.0.1 ytlecture.com
- press
Esc
key on keyboard - press
:wq
- run
- verify changes using
cat /etc/hosts
- Enable tunnel running command :
minikube tunnel
- Then call url in browser : http://ytlecture.com/data
- Hurray 👏 you have successfully deployed your first spring rest api on Kubernetes.
- Stop minikube using :
minikube stop