Files
Deploy-Laboratory/docs/04-01-k3s-nodejs-高级部署.md
jack be97836e0d chore: 清理调试脚本并收敛到 Ansible 流程
移除已废弃的调试/验证脚本与空目录,统一文档与脚本说明到 ansible-playbook 的部署方式,避免失效引用和误用路径。

Made-with: Cursor
2026-03-23 19:18:55 +08:00

83 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 04-01-k3s Node.js 高级部署
> Node.js 属于 `04` 高级部署序列。
> 本文作为 Node.js 主入口:先跑通基础链路,再扩展到自定义端口、存储与构建。
## 前置条件
- 已完成 `01-02-k3s-工作节点.md`
- 已完成 `03-01-k3s-traefik-dashboard.md`(可选,便于观察路由)
- 已完成 `03-04-k3s-cloudflare-tunnel-配置接入.md`(如需外网入口)
## 基础部署步骤
1. 创建 Node.js Deployment默认监听 `3000`
2. 创建 Service`80 -> 3000`
3. 创建 Ingress 或 IngressRoute路径建议 `/node`
## 清单路径(唯一真源)
完整 YAML 不在本文重复粘贴,请以仓库内文件为准(与 Ansible 共用):
| 项 | 路径 / 命令 |
|----|-------------|
| 清单文件 | [`ansible/files/nodejs-demo/04-01-nodejs-demo.yaml`](../ansible/files/nodejs-demo/04-01-nodejs-demo.yaml) |
| 手工应用 | `kubectl apply -f ansible/files/nodejs-demo/04-01-nodejs-demo.yaml` |
| Ansible | `ansible-playbook -i ansible/inventory.ini ansible/playbooks/nodejs-demo-apply.yml -e nodejs_demo_manifest=04-01-nodejs-demo.yaml` |
索引与累积说明见 [`ansible/files/nodejs-demo/README.md`](../ansible/files/nodejs-demo/README.md)。
### 相对上游
本文为 **基线**,无上游清单;以下为资源摘要(便于检索,**以 YAML 文件为准**)。
| 资源 | 要点 |
|------|------|
| Deployment `nodejs-demo` | `node:18-alpine`,监听 **3000**`replicas: 1` |
| Service | `80``targetPort: 3000` |
| Ingress | `entrypoints: web`,路径 **`/node`**,无 `host` |
应用方式:
```bash
kubectl apply -f ansible/files/nodejs-demo/04-01-nodejs-demo.yaml
```
## 基础验证
```bash
kubectl get pod,svc,ing -n default -o wide
curl -s --max-time 3 http://192.168.2.61/node/
curl -s --max-time 3 http://192.168.2.62/node/
```
预期:返回应用内容(如 `Hello World from Node.js`)。
## 失败排查
统一看:`06-01-k3s-networkpolicy-故障排查.md`
## 部署阶段扩展(分项导航)
在本文 `nodejs-demo` 基线上按主题增量实践(建议顺序大致由上到下)。**每篇分项均链接到 `ansible/files/nodejs-demo/` 下累积清单**,并附 **相对上一篇的变更表**;与 [`ansible/playbooks/nodejs-demo-apply.yml`](../ansible/playbooks/nodejs-demo-apply.yml) 共用。
- `04-02-nodejs-镜像与运行命令.md`:镜像 tag、`imagePullPolicy``command`/`args`
- `04-03-nodejs-环境变量与配置注入.md`ConfigMap/Secret、`env`/`envFrom`
- `04-04-nodejs-端口与Service.md``containerPort` 与 Service/Ingress 端口对应
- `04-05-nodejs-资源请求与限制.md``resources`、OOM/CPU 节流
- `04-06-nodejs-探针与健康检查.md`:存活/就绪/启动探针
- `04-07-nodejs-调度与亲和.md``nodeSelector`、亲和、容忍
- `04-08-nodejs-安全上下文.md``securityContext`、非 root、只读根等
- `04-09-nodejs-存储与卷.md``emptyDir`、PVC、配置卷挂载
- `04-10-nodejs-Ingress与Traefik.md`:路径、主机名、`web`/`websecure`
- `04-11-nodejs-副本与滚动发布.md``replicas`、滚动策略
- `04-12-nodejs-TLS与证书.md`Ingress `tls`、HTTPS`03-02` ACME 配合)
- `04-13-nodejs-HPA.md`:水平自动扩缩容
- `04-14-nodejs-GitOps与CI流水线.md`构建镜像、GitOps/CI 闭环
## 下一步
- 返回 `00-00-构建总览.md`,按导航继续。