Files
Deploy-Laboratory/docs/04-07-nodejs-调度与亲和.md
jack 8c43761962 feat: 按 doc_id 重组 ansible/files 与验证框架
- ansible/files 改为与文档 XX-YY 对齐的目录结构,更新相关 playbook 路径
- 新增 scripts/verify.sh 与 ansible/playbooks/verify/*.yml,移除单体 verify-matrix.yml
- 补充 docs/00-02 矩阵状态、00-05 验证框架与流程、00-04 环境与 ylc65 工作机说明
- 增加 k3s 存储准备、Longhorn、local-path 等 playbook 与辅助脚本

Made-with: Cursor
2026-03-26 07:01:14 +08:00

57 lines
2.4 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-07-nodejs-调度与亲和
> 控制 `nodejs-demo` **落在哪些节点**`nodeSelector`、`affinity`、`tolerations`。常用于与 Traefik、存储或合规区域对齐。
## 前置条件
- 已部署 `nodejs-demo``04-01`);集群至少一个节点带可区分 **label**(例如 `kubectl get nodes --show-labels`)。
## 清单路径(唯一真源)
| 本篇完整清单 | [`ansible/files/04-01-nodejs-demo/04-07-nodejs-demo.yaml`](../ansible/files/04-01-nodejs-demo/04-07-nodejs-demo.yaml) |
| 应用 | `kubectl apply -f ansible/files/04-01-nodejs-demo/04-07-nodejs-demo.yaml` |
清单中默认 `nodeSelector: kubernetes.io/hostname: ylc62`,请改为本集群节点名。
## 场景说明(白话)
- **想让 Pod 只跑在某几台机器上**:给节点打标签,在 Pod 里写 **`nodeSelector`**,最简单。
- **规则更复杂**(尽量分散、尽量和某类 Pod 同机架等):用 **affinity亲和**
- **节点有「污点」**像「专属机器」Pod 必须配置 **容忍污点tolerations** 才能调度上去。
### 相对 `04-06` 的变更(原文 → 新文)
| 位置 | 原文(`04-06` | 新文(`04-07` |
|------|-----------------|-----------------|
| `template.spec.nodeSelector` | (无) | `kubernetes.io/hostname: ylc62`(请按环境修改) |
仅当节点具备该标签键值时 Pod 才可调度;否则 **Pending**
## 亲和性(示意,未写入默认累积清单)
**说明**:与 `nodeSelector` **不要硬混用冲突条件**`affinity` / `tolerations` 语法可参考 Kubernetes 文档,在本地改清单或 `kubectl patch` 实验。(示例:`node-role.kubernetes.io/worker` + `Exists`。)
## 容忍污点 tolerations
若目标节点有 `taints`,需在 Pod 上配置对应 `tolerations`,否则无法调度。
## 部署与验证
```bash
kubectl apply -f ansible/files/04-01-nodejs-demo/04-07-nodejs-demo.yaml
kubectl get pod -l app=nodejs-demo -n default -o wide
```
确认 **NODE** 列符合预期。
## 失败排查
- **Pending**`kubectl describe pod` 看 Events`0/X nodes are available`);检查 selector/affinity/taint。
- 与 Traefik DaemonSet 同节点时注意主机端口与防火墙见工作节点、OpenWrt HAProxy 文档)。
## 相关文档
- `01-02-k3s-工作节点.md`
- `02-00-nginx-系列说明.md`(调度思路通用)
- `06-01-k3s-networkpolicy-故障排查.md`