|
| 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 |
0 commit comments