Kiểm tra manifest Kubernetes API
Kiểm tra manifest YAML Kubernetes theo schema chính thức của 8 phiên bản gần nhất, báo API đã bị gỡ và lint tài nguyên, probe, tag image, bảo mật.
Gửi một hoặc nhiều tài liệu YAML (hoặc JSON) qua yaml, file hoặc body thô; kiểu List được tách thành từng đối tượng. Mỗi đối tượng được kiểm tra theo schema OpenAPI của phiên bản Kubernetes version đã chọn (8 bản minor gần nhất, bản vá mới nhất, mặc định là bản mới nhất; /v1/k8s-validate/versions liệt kê) gồm kiểu dữ liệu, trường bắt buộc, giá trị cho phép và — ở chế độ strict (mặc định) — trường lạ như gõ nhầm imagePullPolice. Giá trị null (ví dụ creationTimestamp: null do kubectl sinh ra) được bỏ qua.
apiVersion / kind không còn được phục vụ ở phiên bản đó được báo not_served kèm bản đã gỡ và API thay thế (ví dụ CronJob batch/v1beta1 → batch/v1 từ 1.25), hoặc các phiên bản còn hỗ trợ. Kind không biết (custom resource) được bỏ qua.
lint (mặc định bật) kiểm tra workload (Deployment, StatefulSet, DaemonSet, Job, CronJob, Pod…): image không có tag hoặc dùng :latest, thiếu requests CPU / bộ nhớ và giới hạn bộ nhớ, thiếu readiness / liveness probe, container privileged, cho phép leo thang quyền, chạy bằng root, hostNetwork / hostPID / hostIPC, volume hostPath, capability nguy hiểm, mật khẩu ghi thẳng trong env, chỉ 1 replica, Service NodePort. Schema lấy từ đặc tả OpenAPI của Kubernetes (Apache-2.0), cập nhật hằng tuần.
Markdown · OpenAPI · Postman · llms.txt
Tham số
| Tên | Vị trí | Kiểu | Bắt buộc | Mặc định | |
|---|---|---|---|---|---|
yaml | body | string | có | Một hoặc nhiều tài liệu YAML / JSON (hoặc file / body thô). | |
version | body|query | string | không | Phiên bản minor của Kubernetes, ví dụ 1.35 (mặc định: bản mới nhất có sẵn). | |
strict | body|query | boolean | không | true | Báo lỗi trường không có trong schema. |
lint | body|query | boolean | không | true | Chạy kiểm tra thực hành tốt. |
Ví dụ
curl -X POST "https://apibox.io.vn/v1/k8s-validate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"yaml":"apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: web\nspec:\n replicas: 2\n selector: {matchLabels: {app: web}}\n template:\n metadata: {labels: {app: web}}\n spec:\n containers:\n - name: web\n image: nginx:latest\n ports: [{containerPort: \"80\"}]\n---\napiVersion: batch/v1beta1\nkind: CronJob\nmetadata: {name: report}\n","version":"1.37"}'const res = await fetch('https://apibox.io.vn/v1/k8s-validate', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"yaml": "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: web\nspec:\n replicas: 2\n selector: {matchLabels: {app: web}}\n template:\n metadata: {labels: {app: web}}\n spec:\n containers:\n - name: web\n image: nginx:latest\n ports: [{containerPort: \"80\"}]\n---\napiVersion: batch/v1beta1\nkind: CronJob\nmetadata: {name: report}\n",
"version": "1.37"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/k8s-validate",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"yaml": "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: web\nspec:\n replicas: 2\n selector: {matchLabels: {app: web}}\n template:\n metadata: {labels: {app: web}}\n spec:\n containers:\n - name: web\n image: nginx:latest\n ports: [{containerPort: \"80\"}]\n---\napiVersion: batch/v1beta1\nkind: CronJob\nmetadata: {name: report}\n", "version": "1.37"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/k8s-validate');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"yaml":"apiVersion: apps/v1\\nkind: Deployment\\nmetadata:\\n name: web\\nspec:\\n replicas: 2\\n selector: {matchLabels: {app: web}}\\n template:\\n metadata: {labels: {app: web}}\\n spec:\\n containers:\\n - name: web\\n image: nginx:latest\\n ports: [{containerPort: \\"80\\"}]\\n---\\napiVersion: batch/v1beta1\\nkind: CronJob\\nmetadata: {name: report}\\n","version":"1.37"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Kết quả trả về
{
"kubernetes_version": "1.37",
"release": "v1.37.2",
"strict": true,
"valid": false,
"summary": {
"objects": 2,
"valid": 0,
"invalid": 1,
"not_served": 1,
"skipped": 0,
"lint_errors": 0,
"lint_warnings": 6
},
"results": [
{
"document": 0,
"kind": "Deployment",
"api_version": "apps/v1",
"name": "web",
"status": "invalid",
"errors": [
{
"path": "spec.template.spec.containers.0.ports.0.containerPort",
"message": "type \"string\" is invalid. Expected \"integer\"."
}
],
"lint": [
{
"rule": "image-latest",
"severity": "warning",
"message": "container \"web\": image tag :latest is not reproducible; pin a version or digest",
"path": "spec.template.spec.containers[0].image"
},
{
"rule": "resources-requests",
"severity": "warning",
"message": "container \"web\" has no CPU / memory requests (scheduling and QoS are guessed)",
"path": "spec.template.spec.containers[0].resources.requests"
},
"…"
]
},
{
"document": 1,
"kind": "CronJob",
"api_version": "batch/v1beta1",
"name": "report",
"status": "not_served",
"errors": [
{
"path": "apiVersion",
"message": "batch/v1beta1/CronJob is not served by Kubernetes 1.37 (removed in 1.25; use batch/v1)"
}
],
"available_in": [],
"use_api_version": [
"batch/v1"
]
}
]
}
Ứng dụng
- Kiểm tra manifest hoặc kết quả helm template trước khi kubectl apply
- Tìm API sẽ hỏng khi nâng cấp cluster lên phiên bản Kubernetes mới
- Rà soát bảo mật cơ bản (root, privileged, hostPath) khi review pull request
- Kiểm tra YAML do script hoặc công cụ no-code sinh ra
Hỏi đáp
Có hỗ trợ CRD không?
Custom resource được báo là skipped; chỉ các kind có sẵn của Kubernetes được kiểm tra.
Kiểm tra Helm chart được không?
Hãy render trước (helm template) rồi gửi kết quả; template còn {{ }} chưa phải YAML hợp lệ.
Manifest có bị lưu không?
Không. Manifest được kiểm tra trong bộ nhớ; secret bên trong không bao giờ bị ghi log hay lưu lại.
API liên quan
Tạo UUID
Sinh tối đa 1.000 UUID v4, UUID v7 theo thời gian, ULID, Nano ID hoặc mã hex ngẫu nhiên mỗi request. Ngẫu nhiên an toàn, hỗ trợ chữ in hoa.
⏱Phân tích biểu thức cron
Kiểm tra biểu thức cron và xem các lần chạy tiếp theo theo múi giờ bất kỳ, kèm mô tả dễ hiểu. Hỗ trợ cú pháp cron 5, 6 và 7 trường.
🕒Giờ & múi giờ
Lấy giờ hiện tại ở mọi múi giờ, đổi giữa các múi giờ và Unix timestamp (giây hoặc mili giây), kèm độ lệch UTC và thứ trong tuần cho tối đa 30 múi giờ.