- star 数
- 94
- watcher 数
- 2
- fork 数
- 61
- issue 数
- 1
- 最終更新
- 2019/05/23
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.
Deploy postgres with a persistent volume claim
kubectl create -f specs/postgres.yml
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}")
Build the Spring Boot app
./mvnw -DskipTests package
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
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
Create an external load balancer for your app
kubectl expose deployment spring-boot-postgres-sample --type=LoadBalancer --port=8080
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
Scale your application
kubectl scale deployment spring-boot-postgres-sample --replicas=3
kubectl set image deployment/spring-boot-postgres-sample spring-boot-postgres-sample=<your Docker Hub account>/spring-boot-postgres-on-k8s:v2
Delete the Spring Boot app deployment
kubectl delete -f specs/spring-boot-app.yml
Delete the service for the app
kubectl delete svc spring-boot-postgres-sample
Delete the hostname config map
kubectl delete cm hostname-config
Delete Postgres
kubectl delete -f specs/postgres.yml