How to Build a High‑Availability Microservices System on Kubernetes from Scratch
This guide walks through designing a simple Java Spring Boot microservice architecture, implementing the services, deploying them on a Kubernetes cluster with Eureka registration, adding Prometheus‑Grafana monitoring, configuring logging, tracing, and flow‑control, and validating high availability using real‑time dashboards and tools like Lens.
Overview
This guide demonstrates a complete workflow for building a microservice‑based application, packaging it with Docker, and deploying it on a highly available Kubernetes cluster. All source code, Dockerfiles, and Kubernetes manifests are available at
https://github.com/xiaojiaqi/deploy-microservices-to-a-Kubernetes-cluster.
Microservice Design
The system follows classic microservice principles (high cohesion, low coupling). It consists of three stateless services – a.demo.com, b.demo.com, and c.demo.com – that are invoked sequentially from a simple front‑end page. Service discovery is provided by a lightweight Eureka cluster, allowing each instance to register itself and be discovered by its peers.
Implementation
The implementation is a multi‑module Maven project using Spring Boot:
Front‑end site : a static HTML page that triggers an AJAX call to the back‑end.
Eureka registration center : a Spring Boot Eureka server deployed as a three‑node HA cluster.
Base library : shared utilities and response wrappers that embed a timestamp, thread ID, and instance IP in every API response.
Service modules : three Spring Boot services ( a, b, c) that call the base library and expose a health endpoint /hs for Kubernetes liveness probes.
Configuration files such as application.yml contain profiles for local execution and for Kubernetes deployment, ensuring the same artifact can run in both environments.
Kubernetes Deployment
The cluster is provisioned with the open‑source installer K8seasy (repository: https://github.com/xiaojiaqi/K8seasy_release_page). The installation steps are:
sudo ./installer --genkey -hostlist=192.168.2.1
sudo ./installer -kubernetestarfile kubernetes-server-linux-amd64v1.18.2.tar.gz -masterip 192.168.2.50This creates a three‑node HA Kubernetes cluster, configures the network (e.g., 192.168.2.0/24), and installs the monitoring stack (Prometheus, Grafana, Alertmanager, Kubernetes Dashboard). The services are deployed by applying the YAML manifests stored in the repository:
kubectl apply -f eureka-cluster.yaml
kubectl apply -f a-service.yaml
kubectl apply -f b-service.yaml
kubectl apply -f c-service.yaml
kubectl apply -f monitoring.yamlDocker images are pulled from Docker Hub; the manifests reference the image tags defined in the repository.
High‑Availability, Observability, and Resilience
Service discovery : Eureka instances register automatically, providing load‑balanced routing and failover.
Metrics collection : each service exposes Prometheus metrics (memory usage, HTTP 2xx/4xx/5xx counts, JVM thread count, GC time). Grafana dashboards visualize per‑service JVM metrics.
Logging : Logback is configured to ship logs to Kafka (optional) for centralized collection.
Distributed tracing : Zipkin libraries are added to the services; the Zipkin UI visualizes request flows across a → b → c.
Flow control : Sentinel is integrated to provide rate limiting, circuit breaking, and degradation policies.
Validation steps include accessing the front‑end at www.demo.com, clicking the request button, and observing changing instance information on the page, confirming load‑balancing. Grafana, Zipkin, and Sentinel UIs are used to verify metrics, tracing, and flow‑control behavior.
Multi‑Cluster Management
The installer generates a lens.kubeconfig file. Importing this file into Lens IDE ( https://kuberneteslens.dev) provides a single pane of glass for managing multiple clusters.
Conclusion
The article provides a reproducible end‑to‑end example that covers microservice design, Maven‑based implementation, Docker containerization, HA Kubernetes deployment, and production‑grade observability (metrics, logging, tracing, and flow control). It serves as a practical reference for building and operating a resilient microservice system on Kubernetes.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
IT Architects Alliance
Discussion and exchange on system, internet, large‑scale distributed, high‑availability, and high‑performance architectures, as well as big data, machine learning, AI, and architecture adjustments with internet technologies. Includes real‑world large‑scale architecture case studies. Open to architects who have ideas and enjoy sharing.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
