Using Spring Cloud to develop microservices application and deploy to Kubernetes.
- Externalized configuration: Spring Cloud Config
- Service registry and discovery: Eureka
- Client side load balancing: Ribbon, Feign
- API gateway: Zuul, Spring Cloud Gateway
- Circuit breaker: Hystrix, Turbine
- Distributed tracing: Sleuth, Zipkin
build-images.sh
is used to build docker images. It tags the images with192.168.99.100:5000
prefix for uploading them to a local registry server on192.168.99.100
. Update to the correct address if your registry server's address is not192.168.99.100:5000
. If you don't deploy to Kubernetes, you can remove those prefix.push-images.sh
is used to push docker images to the registry server.deploy-docker.sh
is used to deploy the demo app to docker usingdocker-compose.yml
.undeploy-docker.sh
is used to undeploy the demo app in docker.deploy-kubernetes.sh
is used to deploy the demo app to kubernetes. To deploy to Kubernetes, this demo usesMinikube
.undeploy-kubernetes.sh
is used to undeploy the demo app in kubernetes.- This demo use Spring Cloud Gateway(cloud-gateway) as its api gateway, if you wants to use Zuul, using api-gateway instead.
There are three ways to deploy this demo application.
-
You need to provide RabbitMQ and Zipkin services.
-
RabbitMQ:
Please see https://www.rabbitmq.com/download.html
If using docker, you can use the following command:
docker run -d -p 5672:5672 -p 15672:15672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=amqp --name rabbitmq rabbitmq:management
-
Zipkin:
Please see https://github.com/openzipkin/zipkin
# Download Zipkin server curl -sSL https://zipkin.io/quickstart.sh | bash -s # Start Zipkin server RABBIT_ADDRESSES=localhost RABBIT_USER=admin RABBIT_PASSWORD=amqp java -jar zipkin.jar
If using docker, you can use the following command:
docker run -d -p 9411:9411 -e RABBIT_ADDRESSES=rabbitmq -e RABBIT_USER=admin -e RABBIT_PASSWORD=amqp --link rabbitmq:rabbitmq --name zipkin openzipkin/zipkin
-
-
Edit
config-server/src/main/resources/application.properties
:- Make sure
RABBITMQ_SERVICE_HOST
,RABBITMQ_SERVICE_PORT
,RABBITMQ_SERVICE_USERNAME
andRABBITMQ_SERVICE_PASSWORD
match your RabbitMQ configuration. - Set
APP_CONFIG_DIR
andAPP_LOGGINH_DIR
to your correct file path.
- Make sure
-
Use
java -jar
to start each service, config-server should be started first, service-registry next, then other services. -
Access services with its URL, eg:
cloud-gateway: http://localhost:8080/
auth-service: http://localhost:9000/
account-service: http://localhost:9010/
service-registry: http://localhost:8761/
config-server: http://localhost:8888/
turbine-server: http://localhost:8989/
monitor-dashboard: http://localhost:7979/
zipkin: http://localhost:9411/
- Download rabbitmq:management image.
Tag the image with
192.168.99.100:5000/rabbitmq:management
if you use192.168.99.100:5000
prefix inbuild-images.sh
. - Download openzipkin/zipkin image.
Tag the image with
192.168.99.100:5000/zipkin
if you use192.168.99.100:5000
prefix inbuild-images.sh
. - Edit
microservices-demo/deploy-docker.sh
, setAPP_CONFIG_DIR
andAPP_LOGGINH_DIR
to your correct file path. - Run the script
microservices-demo/build-images.sh
to build docker images. - Run the script
microservices-demo/deploy-docker.sh
to start containers. - Run the script
microservices-demo/undeploy-docker.sh
if you want to stop and remove the containers. - Access a service with its URL (same as Local Deployment)
- Download rabbitmq:management image.
Tag the image with
192.168.99.100:5000/rabbitmq:management
. - Download openzipkin/zipkin image.
Tag the image with
192.168.99.100:5000/zipkin
. - Edit
microservices-demo/kubernetes/config-pv.yaml
, setspec.hostPath.path
to your correct file path. Editmicroservices-demo/kubernetes/log-pv.yaml
, setspec.hostPath.path
to your correct file path. - Run the script
microservices-demo/build-images.sh
to build docker images. - Run the script
microservices-demo/push-images.sh
to upload docker images to registry server. - Run the script
microservices-demo/deploy-kubernetes.sh
to deploy to Kubernetes. - Run the script
microservices-demo/undeploy-kubernetes.sh
if you want to stop and remove the containers. - Access services using command
minikube service SERVICE_NAME
eg:
minikube service cloud-gateway
minikube service auth-service
minikube service account-service
minikube service service-registry
minikube service config-server
minikube service monitor-dashboard
minikube service zipkin