📄 Kubernetes YAML Generator
Kubernetes YAML Generator - Enter name, image, port and replicas to produce a Deployment plus Service manifest. Free, browser-only.
📐 工作原理與說明
應用名取輸入值(為空時用預設名),映象取輸入值(為空時用預設映象),埠取輸入值向下取整(無效時取 80),副本數取輸入值向下取整並保證至少為 1。按模板拼裝 Kubernetes 清單:Deployment 段依次寫入介面版本、資源型別、應用名、副本數、以應用名為值的標籤選擇器,以及容器名、映象與容器埠;隨後以分隔線接 Service 段,寫入介面版本、資源型別、應用名、以應用名為值的選擇器、服務埠與目標埠(二者同為上述埠值)與叢集內訪問型別。輸出時對整段 YAML 做 HTML 轉義後在程式碼塊中展示
生成 Kubernetes 資源清單 YAML。
- 必填欄位:apiVersion、kind、metadata、spec。
- 關聯:Deployment 的 selector 必須與 Pod template 的標籤匹配;Service 通過 selector 選中 Pod。
- 資源:requests 決定排程,limits 決定使用上限,二者應合理設定。
- 建議:同時配置 readiness/liveness 探針,避免流量打入未就緒的 Pod。
Formula & Standard References
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Required fields | apiVersion, kind and metadata.name are the minimum | Kubernetes API reference |
| Resource versioning | apiVersion as group/version; core group omits the group | Kubernetes API conventions |
| Label selectors | selector must match the template labels | Kubernetes API conventions |
⚠️ 使用說明與注意事項
- image: latest 不利於回滾與可重現部署,生產應鎖定具體版本/tag 或 digest。
- Service 的 targetPort 須與容器 containerPort 一致;對外暴露需改 type: NodePort/LoadBalancer 或接 Ingress。
- 生成後 kubectl apply -f 部署;變更映象建議走滾動更新與探針(liveness/readiness)保障可用性。
📋 清單結構
Deployment(副本/映象)+ Service(暴露);用 --- 分隔多文件。資源限制(resources)、探針建議另行補充。