Coder Social home page Coder Social logo

springboot-on-minikube's Introduction

Deploy Spring Boot application on Kubernetes cluster (minikube)

Prerequisites:

Perform the following steps to deploy spring boot app on Minikube :

If you want to start from the scratch without cloning this repository, then perform following steps:

  1. Create project using https://start.spring.io/ with name "springboot-on-minikube"
  2. Then add sample controller for creating rest api
  3. From the terminal cd into your project directory and build project using ./gradlew clean build
  4. Start docker on the system
  5. Build docker image using : docker build -t springboot-on-minikube . Command reference
  6. Run the docker container: docker run -p 8080:8080 springboot-on-minikube and verify calling url localhost:8080/data
  7. Now stop the container service and we will create helm chart.
  8. Run command to create helm chart : helm create ytkubechart
  9. To see helm directory structure : tree ytkubechart
  10. 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"
  1. 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
    
    
  2. Now go into terminal and start minikube using minikube start --driver=docker

  3. Enable docker env using command : eval $(minikube docker-env) Command Reference

  4. Build docker image in minikube : docker build -t springboot-on-minikube .

  5. To see images : minikube image ls

  6. Next install and deploy helm chart on cluster : helm install mychart ytkubechart

  7. Verify the configuration using commands like

      kubectl get pods
      kubectl get service
    
  8. To access api, run command : minikube service mychart-ytkubechart --url Command Reference

  9. Copy url returned by the command mentioned in step : 18 and call that url from browser.

  10. To enable ingress on minikube run following command : minikube addons enable ingress Command reference 1 Ref 2

  11. Verify ingress controller is running : kubectl get pods -n ingress-nginx

  12. 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: []
    
  13. Update version in Chart.yaml file

     version: 0.1.2
    
  14. Now to update our kubernetes configuration, run command in terminal : helm upgrade mychart ytkubechart

  15. Verify ingress service using : kubectl get ingress

  16. 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
  17. verify changes using cat /etc/hosts

  18. Enable tunnel running command : minikube tunnel

  19. Then call url in browser : http://ytlecture.com/data

  20. Hurray ๐Ÿ‘ you have successfully deployed your first spring rest api on Kubernetes.

  21. Stop minikube using : minikube stop

If you want to start by cloning this repository, then perform following steps:

  1. From the terminal cd into your project directory and build project using ./gradlew clean build
  2. Start docker on system
  3. Build docker image using : docker build -t springboot-on-minikube .
  4. Run the docker container: docker run -p 8080:8080 springboot-on-minikube and verify calling url localhost:8080/data
  5. Now stop the container service
  6. start minikube using minikube start --driver=docker
  7. Enable docker env using command : eval $(minikube docker-env) Command Reference
  8. Build docker image in minikube : docker build -t springboot-on-minikube .
  9. To see images : minikube image ls
  10. To enable ingress on minikube run following command : minikube addons enable ingress Command reference 1 Ref 2
  11. Verify ingress controller is running : kubectl get pods -n ingress-nginx
  12. Next install and deploy helm chart on cluster : helm install mychart ytkubechart
  13. Verify ingress service using : kubectl get ingress
  14. 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
  15. verify changes using cat /etc/hosts
  16. Enable tunnel running command : minikube tunnel
  17. Then call url in browser : http://ytlecture.com/data
  18. Hurray ๐Ÿ‘ you have successfully deployed your first spring rest api on Kubernetes.
  19. Stop minikube using : minikube stop

springboot-on-minikube's People

Contributors

kodedge-swapneel avatar swapneelgosavi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.