Skip to content

Commit 0a7012f

Browse files
committed
feat: samples for k8s probe
1 parent d2c0f9e commit 0a7012f

File tree

25 files changed

+547
-8
lines changed

25 files changed

+547
-8
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ A collection of runnable Dubbo-go examples covering configuration, registries, o
2929
* `java_interop`: Demonstrates interoperability between Java and Go Dubbo implementations.
3030
* `llm`: Example of integrating Large Language Models (LLMs) with Dubbo-go.
3131
* `logger`: Logging examples for Dubbo-go applications.
32-
* `metrics`: Shows how to collect and expose metrics from Dubbo-go services, supporting both Prometheus Push and Pull modes. Also includes the `pgw-cleaner` tool for cleaning zombie metrics in Push mode.
32+
* `metrics`: Observability-related samples.
33+
* `metrics/prometheus_grafana`: Shows how to collect and expose metrics from Dubbo-go services, supporting both Prometheus Push and Pull modes. Also includes the `pgw-cleaner` tool for cleaning zombie metrics in Push mode.
34+
* `metrics/probe`: Demonstrates Dubbo-go Kubernetes probe endpoints (`/live`, `/ready`, `/startup`) and deployment usage.
3335
* `mesh`: Proxy-based service mesh example showing how to deploy Dubbo-go services with Envoy on Kubernetes.
3436
* `online_boutique`: Microservices “online boutique” demo built with Dubbo-go.
3537
* `otel/tracing`: Distributed tracing examples using OpenTelemetry.

README_CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
* `java_interop`:展示 Java 与 Go Dubbo 实现之间的互操作能力。
3030
* `llm`:将大模型(LLM)集成到 Dubbo-go 中的示例。
3131
* `logger`:Dubbo-go 应用的日志使用示例。
32-
* `metrics`:展示如何采集并暴露 Dubbo-go 服务的指标,支持 Prometheus Push 和 Pull 两种模式;同时包含用于清理 Push 模式僵尸指标的 `pgw-cleaner` 工具。
32+
* `metrics`:可观测性相关示例。
33+
* `metrics/prometheus_grafana`:展示如何采集并暴露 Dubbo-go 服务指标,支持 Prometheus Push 和 Pull 两种模式;同时包含用于清理 Push 模式僵尸指标的 `pgw-cleaner` 工具。
34+
* `metrics/probe`:演示 Dubbo-go 在 Kubernetes 场景下的探针端点(`/live``/ready``/startup`)及部署方式。
3335
* `mesh`:基于代理的服务网格示例,展示如何在 Kubernetes 上结合 Envoy 部署 Dubbo-go 服务。
3436
* `online_boutique`:基于 Dubbo-go 构建的微服务 “在线商城” 演示项目。
3537
* `otel/tracing`:使用 OpenTelemetry 的分布式链路追踪示例。

metrics/probe/README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
2+
# Dubbo-Go Kubernetes Probe Sample
3+
4+
English | [中文](README_CN.md)
5+
6+
This example demonstrates how to integrate **Kubernetes liveness, readiness, and startup probes** with a Dubbo-Go Triple service.
7+
8+
It showcases how to expose dedicated probe endpoints and how Kubernetes reacts during application startup and warm-up.
9+
10+
11+
## Project Layout
12+
13+
```
14+
metrics/probe/
15+
├── go-server/
16+
│ ├── cmd/main.go # Application entrypoint
17+
│ ├── build.sh # Docker build script
18+
│ └── Dockerfile # Container image definition
19+
└── deploy/
20+
└── server-deployment.yml # Kubernetes deployment
21+
```
22+
23+
24+
## Default Configuration
25+
26+
| Item | Value |
27+
| ------------------- | ----------------------------- |
28+
| Triple service port | `20000` |
29+
| Probe HTTP port | `22222` |
30+
| Probe endpoints | `/live`, `/ready`, `/startup` |
31+
| Client target | `tri://127.0.0.1:20000` |
32+
33+
### Probe Semantics
34+
35+
* `GET /live`
36+
Indicates whether the process is alive.
37+
38+
* `GET /ready`
39+
Indicates whether the service is ready to receive traffic.
40+
41+
* `GET /startup`
42+
Indicates whether the application startup phase has completed.
43+
44+
45+
## Run Locally
46+
47+
### 1️Start the server
48+
49+
```bash
50+
go run ./metrics/probe/go-server/cmd/main.go
51+
```
52+
53+
### 2️Monitor probe endpoints
54+
55+
```bash
56+
watch -n 1 '
57+
for p in live ready startup; do
58+
url="http://127.0.0.1:22222/$p"
59+
60+
body=$(curl -sS --max-time 2 "$url" 2>&1)
61+
code=$(curl -s -o /dev/null --max-time 2 -w "%{http_code}" "$url" 2>/dev/null)
62+
63+
printf "%-8s [%s] %s\n" "$p" "$code" "$body"
64+
done
65+
'
66+
```
67+
68+
### Expected Behavior
69+
70+
| Phase | /live | /ready | /startup |
71+
| -------------------- | ----- | ------ | -------- |
72+
| Process started | 200 | 503 | 503 |
73+
| During warm-up | 200 | 503 | 503 |
74+
| After warm-up (~15s) | 200 | 200 | 200 |
75+
76+
77+
## Kubernetes Probe Configuration
78+
79+
Example probe configuration:
80+
81+
```yaml
82+
livenessProbe:
83+
httpGet:
84+
path: /live
85+
port: 22222
86+
87+
readinessProbe:
88+
httpGet:
89+
path: /ready
90+
port: 22222
91+
92+
startupProbe:
93+
httpGet:
94+
path: /startup
95+
port: 22222
96+
```
97+
98+
99+
## Run on Kubernetes
100+
101+
### Build the image
102+
103+
From the repository root:
104+
105+
```bash
106+
./metrics/probe/go-server/build.sh
107+
```
108+
109+
110+
### Load image into local cluster (if needed)
111+
112+
For example, with Minikube:
113+
114+
```bash
115+
minikube image load dubbo-go-probe-server:latest
116+
```
117+
118+
119+
### Deploy to Kubernetes
120+
121+
```bash
122+
kubectl apply -f metrics/probe/deploy/server-deployment.yml
123+
kubectl rollout status deploy/dubbo-go-probe-server
124+
kubectl get pod -l app=dubbo-go-probe-server
125+
```
126+
127+
128+
### Inspect probe status
129+
130+
```bash
131+
kubectl describe pod -l app=dubbo-go-probe-server
132+
```
133+
134+
### Expected Kubernetes Behavior
135+
136+
* Immediately after deployment:
137+
138+
* `Ready` = `False`
139+
* `ContainersReady` = `False`
140+
141+
* After ~15 seconds (warm-up completed):
142+
143+
* `Ready` = `True`
144+
* `ContainersReady` = `True`
145+
146+
This demonstrates proper separation of:
147+
148+
* Process liveness
149+
* Service readiness
150+
* Startup lifecycle completion

metrics/probe/README_CN.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
2+
# Dubbo-Go Kubernetes 探针示例
3+
4+
[English](README.md) | 中文
5+
6+
7+
本示例演示如何在 Dubbo-Go Triple 服务中集成 **Kubernetes 的 liveness、readiness 和 startup 探针**
8+
9+
通过暴露独立的探针端点,可以清晰地观察应用启动、预热以及就绪阶段在 Kubernetes 中的行为。
10+
11+
12+
## 项目结构
13+
14+
```
15+
metrics/probe/
16+
├── go-server/
17+
│ ├── cmd/main.go # 程序入口
18+
│ ├── build.sh # Docker 构建脚本
19+
│ └── Dockerfile # 镜像定义文件
20+
└── deploy/
21+
└── server-deployment.yml # Kubernetes 部署文件
22+
```
23+
24+
25+
## 默认配置
26+
27+
| 项目 | 默认值 |
28+
| ----------- | ----------------------------- |
29+
| Triple 服务端口 | `20000` |
30+
| 探针 HTTP 端口 | `22222` |
31+
| 探针路径 | `/live`, `/ready`, `/startup` |
32+
| 客户端目标地址 | `tri://127.0.0.1:20000` |
33+
34+
35+
## 探针语义说明
36+
37+
* `GET /live`
38+
表示进程是否存活(进程级健康检查)。
39+
40+
* `GET /ready`
41+
表示服务是否已准备好接收流量。
42+
43+
* `GET /startup`
44+
表示应用是否完成启动阶段。
45+
46+
47+
## 本地运行
48+
49+
### 启动服务
50+
51+
```bash
52+
go run ./metrics/probe/go-server/cmd/main.go
53+
```
54+
55+
56+
### 观察探针状态
57+
58+
```bash
59+
watch -n 1 '
60+
for p in live ready startup; do
61+
url="http://127.0.0.1:22222/$p"
62+
63+
body=$(curl -sS --max-time 2 "$url" 2>&1)
64+
code=$(curl -s -o /dev/null --max-time 2 -w "%{http_code}" "$url" 2>/dev/null)
65+
66+
printf "%-8s [%s] %s\n" "$p" "$code" "$body"
67+
done
68+
'
69+
```
70+
71+
72+
### 预期行为
73+
74+
| 阶段 | /live | /ready | /startup |
75+
| ------------ | ----- | ------ | -------- |
76+
| 进程刚启动 | 200 | 503 | 503 |
77+
| 预热阶段 | 200 | 503 | 503 |
78+
| 预热完成(约 15 秒) | 200 | 200 | 200 |
79+
80+
说明:
81+
82+
* `/live` 只要进程未崩溃就返回 200。
83+
* `/ready``/startup` 在应用完成预热前返回 503。
84+
* 预热完成后,三个端点均返回 200。
85+
86+
87+
## Kubernetes 探针配置示例
88+
89+
```yaml
90+
livenessProbe:
91+
httpGet:
92+
path: /live
93+
port: 22222
94+
95+
readinessProbe:
96+
httpGet:
97+
path: /ready
98+
port: 22222
99+
100+
startupProbe:
101+
httpGet:
102+
path: /startup
103+
port: 22222
104+
```
105+
106+
107+
## 在 Kubernetes 中运行
108+
109+
### 构建镜像
110+
111+
在仓库根目录执行:
112+
113+
```bash
114+
./metrics/probe/go-server/build.sh
115+
```
116+
117+
118+
### 将镜像加载到本地集群
119+
120+
例如使用 Minikube:
121+
122+
```bash
123+
minikube image load dubbo-go-probe-server:latest
124+
```
125+
126+
127+
### 部署到 Kubernetes
128+
129+
```bash
130+
kubectl apply -f metrics/probe/deploy/server-deployment.yml
131+
kubectl rollout status deploy/dubbo-go-probe-server
132+
kubectl get pod -l app=dubbo-go-probe-server
133+
```
134+
135+
136+
### 查看探针状态
137+
138+
```bash
139+
kubectl describe pod -l app=dubbo-go-probe-server
140+
```
141+
142+
143+
### 预期 Kubernetes 行为
144+
145+
* 刚部署时:
146+
147+
* `Ready` = `False`
148+
* `ContainersReady` = `False`
149+
150+
* 约 15 秒后(预热完成):
151+
152+
* `Ready` = `True`
153+
* `ContainersReady` = `True`
154+
155+
这体现了:
156+
157+
* 进程存活检查(Liveness)
158+
* 服务可用性检查(Readiness)
159+
* 启动阶段控制(Startup)
160+
161+
三者的职责分离。
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: dubbo-go-probe-server
5+
labels:
6+
app: dubbo-go-probe-server
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: dubbo-go-probe-server
12+
template:
13+
metadata:
14+
labels:
15+
app: dubbo-go-probe-server
16+
spec:
17+
containers:
18+
- name: server
19+
image: dubbo-go-probe-server:latest
20+
imagePullPolicy: IfNotPresent
21+
ports:
22+
- containerPort: 20000
23+
name: triple
24+
- containerPort: 22222
25+
name: probe
26+
livenessProbe:
27+
httpGet:
28+
path: /live
29+
port: probe
30+
initialDelaySeconds: 5
31+
periodSeconds: 10
32+
readinessProbe:
33+
httpGet:
34+
path: /ready
35+
port: probe
36+
initialDelaySeconds: 5
37+
periodSeconds: 5
38+
startupProbe:
39+
httpGet:
40+
path: /startup
41+
port: probe
42+
failureThreshold: 30
43+
periodSeconds: 1

metrics/probe/go-server/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine:3.19
2+
WORKDIR /app
3+
COPY metrics/probe/go-server/probeApp /app/server
4+
5+
EXPOSE 20000 22222
6+
ENTRYPOINT ["/app/server"]

0 commit comments

Comments
 (0)