How to Build a High‑Availability Microservices System on Kubernetes – A Complete Guide
This guide walks you through designing a simple front‑back separation microservice architecture, implementing it with Java Spring Boot, deploying multiple instances with Eureka, adding Prometheus‑Grafana monitoring, logging, tracing, flow control, and finally installing Kubernetes using K8seasy and verifying high‑availability across the cluster.
Microservice Design
The system follows Martin Fowler’s microservice principles of high cohesion and low coupling. A simple three‑service chain a.demo.com → b.demo.com → c.demo.com illustrates request flow. To achieve reliability each service runs multiple instances and registers with a Eureka service registry, which provides dynamic discovery and load balancing across instances.
Observability is built with Prometheus and Grafana for metrics (CPU, memory, HTTP error counts, JVM thread count, GC time, etc.). Application logs are streamed to Kafka to avoid container‑local I/O, and distributed tracing is enabled via Zipkin, which propagates a unique trace ID across service calls.
Flow‑control mechanisms—circuit breaking, rate limiting, and degradation—are implemented with Alibaba Sentinel, which integrates seamlessly with Spring Cloud.
Implementation Details
The front‑end is a static HTML page that issues an AJAX request to an Nginx‑proxied endpoint. Nginx forwards the request to a.demo.com, which in turn calls b.demo.com, and finally c.demo.com. The back‑end consists of three Maven modules (a, b, c) that share a common utility library and a Eureka server for registration.
Each service exposes a health‑check endpoint /hs so Kubernetes can perform liveness and readiness probes. Configuration files are written in YAML, allowing seamless switching between local execution and container deployment.
Kubernetes Deployment
A three‑node HA Kubernetes cluster can be provisioned with the open‑source installer K8seasy . The installer bundles required container images and supports multiple Kubernetes versions.
Generate cluster keys: sudo ./installer --genkey -hostlist=192.168.2.1 Create the cluster (example uses Kubernetes v1.18.2):
sudo ./installer -kubernetestarfile kubernetes-server-linux-amd64v1.18.2.tar.gz -masterip 192.168.2.50Verify installation via the Kubernetes dashboard (port 10000) and access Alertmanager (8080) and Grafana (8081, default credentials admin/admin).
Docker images for the services are hosted on Docker Hub. Applying the provided YAML manifests creates Deployments, Services, and a three‑replica Eureka StatefulSet, enabling automatic start‑up and HA.
High‑Availability Verification
Verification steps include:
Open the front‑end at www.demo.com and click the request button; response times from each instance are displayed.
Run a simple script that issues a request every three seconds to simulate continuous traffic.
Inspect the Zipkin UI ( zipkin.demo.com) to view end‑to‑end trace details for each request.
Use the Sentinel console to monitor real‑time metrics, rate‑limiting counters, and circuit‑breaker status.
View Grafana dashboards for JVM heap usage, GC pauses, error counts, and overall service health.
These checks demonstrate that the failure of any single instance does not affect overall system functionality, confirming the high‑availability design.
Repository
All source code, Dockerfiles, and Kubernetes YAML manifests are available at:
https://github.com/xiaojiaqi/deploy-microservices-to-a-Kubernetes-clusterSigned-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.
