Giter Site home page Giter Site logo

omaradam61 / spring-boot-postgres-on-k8s-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mkjelland/spring-boot-postgres-on-k8s-sample

0.0 0.0 0.0 60 KB

License: Apache License 2.0

Shell 43.33% Java 19.87% HTML 3.35% Batchfile 33.45%

spring-boot-postgres-on-k8s-sample's Introduction

spring-boot-postgres-on-k8s

This demo deploys a simple Spring Boot web application that connects to Postgres onto a Kubernetes cluster.

You can watch this demo along with an introduction to Kubernetes concepts here.

Prerequisites

  • Kubernetes cluster with kubectl installed and configured to use your cluster
  • docker cli installed, you must be signed into your Docker Hub account

Deploy Spring Boot app and Postgres on Kubernetes

  1. Deploy postgres with a persistent volume claim

    kubectl create -f specs/postgres.yml
    
  2. Create a config map with the hostname of Postgres

    kubectl create configmap hostname-config --from-literal=postgres_host=$(kubectl get svc postgres -o jsonpath="{.spec.clusterIP}")
    
  3. Build the Spring Boot app

    ./mvnw -DskipTests package
    
  4. Build a Docker image and push the image to Docker Hub

    docker build -t <your Docker Hub account>/spring-boot-postgres-on-k8s:v1 .
    docker push <your Docker Hub account>/spring-boot-postgres-on-k8s:v1
    
  5. Replace <your Docker Hub account> with your account name in specs/spring-boot-app.yml, then deploy the app

    kubectl create -f specs/spring-boot-app.yml
    
  6. Create an external load balancer for your app

    kubectl expose deployment spring-boot-postgres-sample --type=LoadBalancer --port=8080
    
  7. Get the External IP address of Service, then the app will be accessible at http://<External IP Address>:8080

    kubectl get svc spring-boot-postgres-sample
    

    Note: It may take a few minutes for the load balancer to be created

  8. Scale your application

    kubectl scale deployment spring-boot-postgres-sample --replicas=3
    

Updating your application

  1. Update the image that the containers in your deployment are using
    kubectl set image deployment/spring-boot-postgres-sample spring-boot-postgres-sample=<your Docker Hub account>/spring-boot-postgres-on-k8s:v2
    

Deleting the Resources

  1. Delete the Spring Boot app deployment

    kubectl delete -f specs/spring-boot-app.yml
    
  2. Delete the service for the app

    kubectl delete svc spring-boot-postgres-sample
    
  3. Delete the hostname config map

    kubectl delete cm hostname-config
    
  4. Delete Postgres

    kubectl delete -f specs/postgres.yml
    

spring-boot-postgres-on-k8s-sample's People

Contributors

mkjelland 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.