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.shis used to build docker images. It tags the images with192.168.99.100:5000prefix 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.shis used to push docker images to the registry server.deploy-docker.shis used to deploy the demo app to docker usingdocker-compose.yml.undeploy-docker.shis used to undeploy the demo app in docker.deploy-kubernetes.shis used to deploy the demo app to kubernetes. To deploy to Kubernetes, this demo usesMinikube.undeploy-kubernetes.shis 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.jarIf 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_USERNAMEandRABBITMQ_SERVICE_PASSWORDmatch your RabbitMQ configuration. - Set
APP_CONFIG_DIRandAPP_LOGGINH_DIRto your correct file path.
- Make sure
-
Use
java -jarto 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:managementif you use192.168.99.100:5000prefix inbuild-images.sh. - Download openzipkin/zipkin image.
Tag the image with
192.168.99.100:5000/zipkinif you use192.168.99.100:5000prefix inbuild-images.sh. - Edit
microservices-demo/deploy-docker.sh, setAPP_CONFIG_DIRandAPP_LOGGINH_DIRto your correct file path. - Run the script
microservices-demo/build-images.shto build docker images. - Run the script
microservices-demo/deploy-docker.shto start containers. - Run the script
microservices-demo/undeploy-docker.shif 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.pathto your correct file path. Editmicroservices-demo/kubernetes/log-pv.yaml, setspec.hostPath.pathto your correct file path. - Run the script
microservices-demo/build-images.shto build docker images. - Run the script
microservices-demo/push-images.shto upload docker images to registry server. - Run the script
microservices-demo/deploy-kubernetes.shto deploy to Kubernetes. - Run the script
microservices-demo/undeploy-kubernetes.shif you want to stop and remove the containers. - Access services using command
minikube service SERVICE_NAMEeg:
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