Skip to content

Commit a2874b2

Browse files
Merge pull request #28 from yangchuansheng/fix/1024mi-resource-ladder
fix(docker-to-sealos): normalize 1024Mi resource ladder
2 parents 253d9fb + e6ed379 commit a2874b2

10 files changed

Lines changed: 542 additions & 148 deletions

skills/docker-to-sealos/SKILL.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ If validation fails, fix template/rules/examples first.
174174
- MySQL cluster must follow upgraded structure (`kb.io/database: ac-mysql-8.0.30-1`, `clusterDefinitionRef: apecloud-mysql`, `clusterVersionRef: ac-mysql-8.0.30-1`, `tolerations: []`).
175175
- Redis cluster must follow upgraded structure (`componentDef: redis-7`, `componentDef: redis-sentinel-7`, `serviceVersion: 7.2.7`, main data PVC `1Gi`, topology `replication`).
176176
- Database cluster component resources must use `limits(cpu=500m,memory=512Mi)` and `requests(cpu=50m,memory=51Mi)` unless source docs explicitly require otherwise.
177+
- All managed workload container resources must use the Sealos resource ladder: `limits.cpu` only `100m/200m/500m/1/2/3/4/8`, `limits.memory` only `128Mi/256Mi/512Mi/1024Mi/2G/4G/8G/16G`, and `requests` must be derived from `limits` by dropping the last numeric digit (`500m→50m`, `512Mi→51Mi`, `1→100m`, `1024Mi→102Mi`). Do not invent non-ladder values.
177178
- Secret naming:
178179
- MongoDB: `${{ defaults.app_name }}-mongo-mongodb-account-root` (or `${{ defaults.app_name }}-mongodb-mongodb-account-root` when the MongoDB cluster name uses `-mongodb`)
179180
- Redis: `${{ defaults.app_name }}-redis-redis-account-default` (legacy `${{ defaults.app_name }}-redis-account-default` may be accepted for backward compatibility)
@@ -182,13 +183,33 @@ If validation fails, fix template/rules/examples first.
182183

183184
### Baseline runtime defaults
184185

185-
Unless source docs explicitly require otherwise, use:
186+
Unless source docs explicitly require otherwise, use the lightweight app ladder entry:
186187

187188
- container limits: `cpu=200m`, `memory=256Mi`
188189
- container requests: `cpu=20m`, `memory=25Mi`
189190
- `revisionHistoryLimit: 1`
190191
- `automountServiceAccountToken: false`
191192

193+
For higher resource needs, move only to another allowed `limits` ladder entry and recompute `requests` from that `limits` value.
194+
195+
### Browser / remote desktop resource validation
196+
197+
For browser, VNC, WebRTC desktop, Xvfb, Selkies, noVNC, Kasm, or remote-desktop-style containers:
198+
199+
- Do not treat a short smoke test as proof of a stable minimum memory value.
200+
- Validate memory with a fresh deployment, not only a patched warm pod.
201+
- Exercise cold start until readiness, a lightweight page, a real/medium page, an interactive/search page, and a 60s post-smoke stability check.
202+
- If observed cgroup memory reaches more than 80% of the limit during smoke, move to the next allowed Sealos memory ladder value.
203+
- Keep requests derived from limits according to the Sealos resource ladder.
204+
205+
Example:
206+
- Bad: Chrome passes a short smoke at `512Mi` but reaches `503Mi`; shipping `512Mi` as the stable minimum is unsafe.
207+
- Good: raise to `1024Mi`, set request to `102Mi`, rerun smoke and stability checks.
208+
209+
For Chrome + Xvfb + Selkies with 4K max display, use at least:
210+
- limits: `cpu=200m`, `memory=1024Mi`
211+
- requests: `cpu=20m`, `memory=102Mi`
212+
192213
### Defaults vs inputs
193214

194215
- `defaults` for generated values (`app_name`, `app_host`, random passwords/keys).

skills/docker-to-sealos/references/conversion-mappings.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ env:
521521

522522
## Resource Limits Mapping
523523

524+
Compose resource values must be normalized to the Sealos ladder. Use Compose limits only to choose the nearest allowed `limits` tier. Normalize 1G-class memory to `1024Mi`. Ignore Compose reservations for `requests`; Sealos `requests` are derived from the selected `limits` by dropping the last numeric digit, so `1024Mi` maps to `102Mi`.
525+
524526
### Docker Compose
525527
```yaml
526528
services:
@@ -544,11 +546,11 @@ spec:
544546
- name: ${{ defaults.app_name }}
545547
resources:
546548
limits:
547-
cpu: 1000m
549+
cpu: 1
548550
memory: 1024Mi
549551
requests:
550-
cpu: 500m
551-
memory: 512Mi
552+
cpu: 100m
553+
memory: 102Mi
552554
```
553555

554556
## Health Check Mapping

skills/docker-to-sealos/references/frappe-bench.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ Do not mix these models blindly. If a repo's `docker/docker-compose.yml` uses `f
1717

1818
- Database services from Compose (`mariadb`, `mysql`, `redis`) should follow the Sealos database strategy. Redis must use the KubeBlocks Redis `Cluster` and its generated Secret (`${{ defaults.app_name }}-redis-redis-account-default`) unless the user explicitly asks for raw containers.
1919
- If using a prebuilt Frappe image with mounted `sites` and `logs` PVCs, set pod `securityContext.fsGroup: 1000` so the `frappe` user can write mounted volumes.
20-
- Init containers that run `bench init`, `bench new-site`, `bench migrate`, or app install steps must set explicit resources. Do not rely on namespace defaults; `64Mi` memory is too small. Use at least:
21-
- light config init: `requests.memory: 128Mi`, `limits.memory: 256Mi`
22-
- `bench new-site` / app install / migrate: `requests.memory: 512Mi`, `limits.memory: 2Gi`
20+
- Init containers that run `bench init`, `bench new-site`, `bench migrate`, or app install steps must set explicit resources from the Sealos ladder. Do not rely on namespace defaults; `64Mi` memory is too small. Use at least:
21+
- light config init: `limits.memory: 256Mi`, `requests.memory: 25Mi`
22+
- `bench new-site` / app install / migrate: `limits.memory: 2G`, `requests.memory: 200Mi`
23+
- choose matching ladder CPU values and derive CPU requests the same way, for example `limits.cpu: 500m``requests.cpu: 50m`
2324
- Bootstrap scripts must be idempotent and recover from partial initialization:
2425
- create `sites/common_site_config.json` if a fresh PVC hides the image's bundled file
2526
- use `bench new-site --force` for first-site creation when the database may contain residue from a previous failed attempt

skills/docker-to-sealos/references/must-rules-map.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ must_rules:
236236
enforcement:
237237
type: rule
238238
target: R019
239+
- must: "All managed workload container resources must use the Sealos resource ladder: `limits.cpu` only `100m/200m/500m/1/2/3/4/8`, `limits.memory` only `128Mi/256Mi/512Mi/1024Mi/2G/4G/8G/16G`, and `requests` must be derived from `limits` by dropping the last numeric digit (`500m→50m`, `512Mi→51Mi`, `1→100m`, `1024Mi→102Mi`). Do not invent non-ladder values."
240+
enforcement:
241+
type: rule
242+
target: R038
239243
- must: "MongoDB: `${{ defaults.app_name }}-mongo-mongodb-account-root` (or `${{ defaults.app_name }}-mongodb-mongodb-account-root` when the MongoDB cluster name uses `-mongodb`)"
240244
enforcement:
241245
type: rule
@@ -254,12 +258,12 @@ must_rules:
254258
target: R007
255259
- must: "container limits: `cpu=200m`, `memory=256Mi`"
256260
enforcement:
257-
type: manual
258-
note: "Requires runtime-default validation with source-doc override awareness."
261+
type: rule
262+
target: R038
259263
- must: "container requests: `cpu=20m`, `memory=25Mi`"
260264
enforcement:
261-
type: manual
262-
note: "Requires runtime-default validation with source-doc override awareness."
265+
type: rule
266+
target: R038
263267
- must: "`revisionHistoryLimit: 1`"
264268
enforcement:
265269
type: rule

skills/docker-to-sealos/references/rules-registry.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ rules:
7676
- id: R019
7777
description: Database cluster component resources must use limits cpu=500m/memory=512Mi and requests cpu=50m/memory=51Mi.
7878
severity: error
79+
- id: R038
80+
description: Managed workload container resources must use allowed Sealos limits ladder values and derive requests from limits.
81+
severity: error
7982
- id: R020
8083
description: Service spec.ports entries must define non-empty name fields in template artifacts.
8184
severity: error

skills/docker-to-sealos/references/sealos-specs.md

Lines changed: 112 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -903,146 +903,127 @@ spec:
903903

904904
### Resource Limit Configuration
905905

906-
**Important: The resources field of all containers must include both requests and limits!**
906+
**Important: The resources field of all containers must include both requests and limits.**
907+
908+
All containers in application Deployments or StatefulSets must use the fixed Sealos resource ladder. Do not invent intermediate values during template generation or resource tuning.
909+
910+
Allowed `limits.cpu` values use canonical Kubernetes quantities:
911+
912+
- `100m` (0.1 core)
913+
- `200m` (0.2 core)
914+
- `500m` (0.5 core)
915+
- `1`
916+
- `2`
917+
- `3`
918+
- `4`
919+
- `8`
920+
921+
Allowed `limits.memory` values:
922+
923+
- `128Mi`
924+
- `256Mi`
925+
- `512Mi`
926+
- `1024Mi`
927+
- `2G`
928+
- `4G`
929+
- `8G`
930+
- `16G`
931+
932+
`requests` must be derived from `limits` by dropping the last numeric digit:
933+
934+
| limits | requests |
935+
|--------|----------|
936+
| `cpu: 100m` | `cpu: 10m` |
937+
| `cpu: 200m` | `cpu: 20m` |
938+
| `cpu: 500m` | `cpu: 50m` |
939+
| `cpu: 1` | `cpu: 100m` |
940+
| `cpu: 2` | `cpu: 200m` |
941+
| `cpu: 3` | `cpu: 300m` |
942+
| `cpu: 4` | `cpu: 400m` |
943+
| `cpu: 8` | `cpu: 800m` |
944+
| `memory: 128Mi` | `memory: 12Mi` |
945+
| `memory: 256Mi` | `memory: 25Mi` |
946+
| `memory: 512Mi` | `memory: 51Mi` |
947+
| `memory: 1024Mi` | `memory: 102Mi` |
948+
| `memory: 2G` | `memory: 200Mi` |
949+
| `memory: 4G` | `memory: 400Mi` |
950+
| `memory: 8G` | `memory: 800Mi` |
951+
| `memory: 16G` | `memory: 1600Mi` |
952+
953+
**Default lightweight application quota:**
907954

908-
All containers in application Deployments or StatefulSets must have resource quotas configured:
955+
```yaml
956+
resources:
957+
requests:
958+
cpu: 20m
959+
memory: 25Mi
960+
limits:
961+
cpu: 200m
962+
memory: 256Mi
963+
```
964+
965+
**Standard backend or broker quota after validation:**
909966

910967
```yaml
911-
containers:
912-
- name: ${{ defaults.app_name }}
913-
image: example/app:1.0.0
914-
imagePullPolicy: IfNotPresent
915-
resources:
916-
requests:
917-
cpu: 100m # Minimum CPU request (required)
918-
memory: 128Mi # Minimum memory request (required)
919-
limits:
920-
cpu: 500m # CPU upper limit (required)
921-
memory: 512Mi # Memory upper limit (required)
968+
resources:
969+
requests:
970+
cpu: 50m
971+
memory: 51Mi
972+
limits:
973+
cpu: 500m
974+
memory: 512Mi
922975
```
923976

924-
**Quota setting guidelines**:
925-
926-
1. **Lightweight frontend applications** (static file serving, simple web applications):
927-
```yaml
928-
resources:
929-
requests:
930-
cpu: 20m
931-
memory: 25Mi
932-
limits:
933-
cpu: 200m
934-
memory: 256Mi
935-
```
936-
937-
2. **Standard backend applications** (API services, medium-load applications):
938-
```yaml
939-
resources:
940-
requests:
941-
cpu: 100m
942-
memory: 256Mi
943-
limits:
944-
cpu: 1000m
945-
memory: 1Gi
946-
```
947-
948-
3. **Heavy-load applications** (AI processing, video processing, big data processing):
949-
```yaml
950-
resources:
951-
requests:
952-
cpu: 500m
953-
memory: 512Mi
954-
limits:
955-
cpu: 2000m
956-
memory: 2Gi
957-
```
958-
959-
4. **AI/Machine Learning applications** (requiring GPU or large computational resources):
960-
```yaml
961-
resources:
962-
requests:
963-
cpu: 1000m
964-
memory: 1Gi
965-
limits:
966-
cpu: 4000m
967-
memory: 4Gi
968-
```
969-
970-
**Quota setting explanation**:
971-
972-
- **requests (request values)**: The minimum resources guaranteed for the container
973-
- CPU uses `m` units (1000m = 1 CPU core)
974-
- Memory uses `Mi` or `Gi` units
975-
- Recommendation: Set requests to 70-80% of actual usage
976-
977-
- **limits (limit values)**: The maximum resources the container can use
978-
- CPU can burst up to the limit value
979-
- Memory exceeding the limit will trigger OOM Kill
980-
- Recommendation: Set limits to 2-4 times the requests
981-
982-
**Golden rules for quota settings**:
983-
984-
1. **Always set both requests and limits**
985-
- Incorrect: Setting only requests may lead to resource starvation
986-
- Incorrect: Setting only limits may cause scheduling failures
987-
- Correct: Setting both guarantees performance and stability
988-
989-
2. **Reasonable requests/limits ratio**
990-
- CPU: limits can be 2-10 times the requests (CPU is compressible)
991-
- Memory: limits should be 1.5-2 times the requests (memory is incompressible)
992-
993-
3. **Adjust based on application type**
994-
- Compute-intensive: Increase CPU quota
995-
- Memory-intensive: Increase memory quota
996-
- I/O-intensive: Balance CPU and memory
997-
998-
4. **Monitor and adjust**
999-
- Use conservative quotas for initial deployment
1000-
- Monitor actual resource usage
1001-
- Dynamically adjust based on monitoring data
1002-
1003-
**Comparison examples**:
977+
**Heavy workload quota:**
1004978

1005979
```yaml
1006-
# Incorrect: No resource limits
1007-
containers:
1008-
- name: app
1009-
image: app:1.0.0
1010-
imagePullPolicy: IfNotPresent
1011-
1012-
# Incorrect: Only requests
1013-
containers:
1014-
- name: app
1015-
image: app:1.0.0
1016-
imagePullPolicy: IfNotPresent
1017-
resources:
1018-
requests:
1019-
cpu: 100m
1020-
memory: 128Mi
1021-
1022-
# Incorrect: Only limits
1023-
containers:
1024-
- name: app
1025-
image: app:1.0.0
1026-
imagePullPolicy: IfNotPresent
1027-
resources:
1028-
limits:
1029-
cpu: 500m
1030-
memory: 512Mi
1031-
1032-
# Correct: Both requests and limits are present
1033-
containers:
1034-
- name: app
1035-
image: app:1.0.0
1036-
imagePullPolicy: IfNotPresent
1037-
resources:
1038-
requests:
1039-
cpu: 100m
1040-
memory: 128Mi
1041-
limits:
1042-
cpu: 500m
1043-
memory: 512Mi
980+
resources:
981+
requests:
982+
cpu: 200m
983+
memory: 200Mi
984+
limits:
985+
cpu: 2
986+
memory: 2G
1044987
```
1045988

989+
**Invalid examples:**
990+
991+
```yaml
992+
# Incorrect: non-ladder values
993+
resources:
994+
requests:
995+
cpu: 30m
996+
memory: 160Mi
997+
limits:
998+
cpu: 300m
999+
memory: 384Mi
1000+
1001+
# Incorrect: requests copied from old ratio guidance instead of deriving from limits
1002+
resources:
1003+
requests:
1004+
cpu: 100m
1005+
memory: 256Mi
1006+
limits:
1007+
cpu: 1
1008+
memory: 1024Mi
1009+
1010+
# Incorrect: decimal G form is not the canonical 1G-class ladder value
1011+
resources:
1012+
requests:
1013+
cpu: 100m
1014+
memory: 100Mi
1015+
limits:
1016+
cpu: 1
1017+
memory: 1G
1018+
```
1019+
1020+
**Tuning guidance:**
1021+
1022+
1. Move only between allowed `limits` ladder values.
1023+
2. Recompute `requests` from the selected `limits`; do not preserve old requests.
1024+
3. If a StatefulSet fails readiness at a lower resource tier, recreate or cleanly roll the Pod before testing the next tier so a stale non-ready Pod is not mistaken for the next tier's result.
1025+
4. Choose the lowest tier that becomes Ready and passes application-level probes.
1026+
10461027
## Image Configuration Specification
10471028

10481029
### Image Pull Policy

0 commit comments

Comments
 (0)