Cloud Native 19 min read

Build a High‑Availability Microservices System on Kubernetes: A Step‑by‑Step Guide

This comprehensive guide walks you through designing a simple front‑end/back‑end microservice architecture, implementing it with Spring Boot, adding service discovery, monitoring, logging, tracing, and flow control, and finally deploying the entire system on a Kubernetes cluster with high availability and verification steps.

Architecture Talk
Architecture Talk
Architecture Talk
Build a High‑Availability Microservices System on Kubernetes: A Step‑by‑Step Guide

Chapter 1: Microservice Project Design

1.1 Microservice Design Philosophy

Microservices split functionality into independent, single‑purpose modules, achieving high cohesion and low coupling, and can be implemented in any language; this example uses Java Spring Boot with RESTful RPC.

Microservices also require careful consideration of reliability, scalability, and observability.

1.2 Practical Design and Improvements

A simple microservice architecture is proposed where a front‑end site (www.demo.com) calls a chain of services a.demo.com → b.demo.com → c.demo.com, each exposing a health check endpoint for Kubernetes.

1.3.1 Adding Multiple Instances and a Service Registry

To improve reliability, each service runs multiple instances and uses a registry (e.g., Eureka) for service discovery.

In Kubernetes, the registry imposes no restrictions; the services can run unchanged.

1.3.2 Monitoring System (Metrics)

Prometheus and Grafana are used for metrics collection, exposing JVM metrics, error counts, and request latency.

1.3.3 Logging System

Logs are sent directly to Kafka to avoid disk I/O on containers, using Logback configuration.

1.3.4 Tracing System

Zipkin is integrated for distributed tracing, requiring only a library dependency.

1.3.5 Flow Control

Sentinel is employed for rate limiting, circuit breaking, and degradation to protect the system under high load.

Chapter 2: Microservice Implementation

2.1 Front‑End Site

The front‑end displays a page with a button that triggers an AJAX request to the back‑end via Nginx, which forwards to a.demo.com, then to b.demo.com and c.demo.com, finally returning the result to the user.

2.2 Service Registry

Simple Eureka registration code: @EnableEurekaServer Configuration files are adjusted for high‑availability deployment in Kubernetes.

2.3 Base Library

A shared library contains common dependencies and utilities, allowing each microservice to focus on business logic.

2.4 Service Implementations (a.demo.com, b.demo.com, c.demo.com)

Each service implements a health check endpoint /hs for Kubernetes readiness probes.

Chapter 3: Kubernetes Deployment

Kubernetes is installed using the K8seasy tool, which provides a one‑click installation of a production‑grade cluster.

Generate SSH keys: sudo ./installer --genkey -hostlist=192.168.2.1 Create the cluster:

sudo ./installer -kubernetestarfile kubernetes-server-linux-amd64v1.18.2.tar.gz -masterip 192.168.2.50

After installation, the dashboard, Alertmanager, Grafana, and Prometheus are accessible via the master node IP.

3.1 Monitoring Components

Grafana dashboards display JVM metrics for each Java service.

Chapter 4: High‑Availability Deployment and Validation

Microservice JARs are built and container images are pushed to Docker Hub, then deployed with Kubernetes YAML files.

4.1 Service Deployment

Apply each YAML file; the services become visible in the Kubernetes dashboard.

4.2 Front‑End Verification

Access http://www.demo.com, click the request button, and observe changing instance information, confirming load distribution.

4.3 Call Chain Verification

Open Zipkin at zipkin.demo.com to view detailed traces of each request.

4.4 Rate Limiting and Circuit Breaking

Use Sentinel’s UI (default credentials: sentinel) to monitor services and configure flow control rules.

4.5 Application State Monitoring

Grafana shows memory usage, heap size, error counts, and other JVM metrics for all services.

By following these steps, you can build, deploy, and operate a robust, high‑availability microservice system on Kubernetes.

DockermicroservicesKubernetesPrometheusSpring Boot
Architecture Talk
Written by

Architecture Talk

Rooted in the "Dao" of architecture, we provide pragmatic, implementation‑focused architecture content.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.