对齐文件规范

This commit is contained in:
2026-03-27 16:58:41 +08:00
parent 231b6713c4
commit 31709425e2
235 changed files with 5433 additions and 2850 deletions

View File

@@ -2,6 +2,14 @@
> 这篇只讲一件事:在 K3s 里,如何控制“数据最终落到宿主机哪个目录”。
## TL;DR
- **自动化验收**`./scripts/verify.sh run 03-05`
- **关键前置**:按本文「前置条件」准备环境变量/Secret/入口 IP
- **成功判据**:达到本文「预期」且 playbook 断言通过
- **排障**:见本文「排障」
## 先说结论
- **方法一(推荐)`local-path-config`**:给 `local-path` 动态供给指定“基路径”。
@@ -34,9 +42,9 @@ kubectl -n kube-system get configmap local-path-config -o yaml > /tmp/local-path
kubectl -n kube-system edit configmap local-path-config
```
**本仓库实验室真源**(四节点 **10G+32G**、K3s `--data-dir=/storage` 统一拓扑):[`ansible/files/03-05-local-path-config/local-path-config-lab.json`](../ansible/files/03-05-local-path-config/local-path-config-lab.json) —— 仅含 **`DEFAULT_PATH_FOR_NON_LISTED_NODES``/storage/storage`**。应用方式:
**本仓库实验室真源**(四节点 **10G+32G**、K3s `--data-dir=/storage` 统一拓扑):[`ansible/files/03-05/local-path-config-lab.json`](../ansible/files/03-05/local-path-config-lab.json) —— 仅含 **`DEFAULT_PATH_FOR_NON_LISTED_NODES``/storage/storage`**。应用方式:
- Ansible`ansible-playbook -i inventory.ini playbooks/apply-local-path-config-lab.yml`,或在 `group_vars/all.yml``longhorn_apply_local_path_lab: true` 后执行 `longhorn-install.yml`(见 `01-06``03-07`)。
- Ansible`ansible-playbook -i inventory.ini playbooks/verify/03-05.yml`,或在 `group_vars/all.yml``longhorn_apply_local_path_lab: true` 后执行 `03-07.yml`(见 `01-06``03-07`)。
- 手工:备份后编辑 ConfigMap`config.json` 与真源 JSON 对齐,再 `rollout restart` provisioner。
配置结构示意(**四节点统一基路径**时只需 `DEFAULT` 一条;请与现有 JSON 合并,不要盲目整段覆盖):
@@ -65,12 +73,12 @@ kubectl -n kube-system rollout restart deploy/local-path-provisioner 2>/dev/null
### 3) 用 demo 验证PVC -> PV -> 节点 -> 落地目录)
Demo 清单:[`ansible/files/03-05-local-path-demo/local-path-pvc-demo.yaml`](../ansible/files/03-05-local-path-demo/local-path-pvc-demo.yaml)
Demo 清单:[`ansible/files/03-05/local-path-pvc-demo.yaml`](../ansible/files/03-05/local-path-pvc-demo.yaml)
> 该 demo 已包含 `nodeSelector` 固定节点(示例为 `ylc61`),使用前请按你的节点主机名修改。
```bash
kubectl apply -f ansible/files/03-05-local-path-demo/local-path-pvc-demo.yaml
kubectl apply -f ansible/files/03-05/local-path-pvc-demo.yaml
kubectl rollout status deploy/nginx-local-pvc-demo --timeout=180s
```
@@ -148,7 +156,8 @@ echo "node=$NODE path=$PATH_ON_NODE"
适用:单节点、实验环境,或者你明确要写死某个宿主机目录。
最小完整示例(可直接 `kubectl apply -f`,非空行逐行注释):
最小完整示例真源:[`ansible/files/03-05/nginx-hostpath-demo.yaml`](../ansible/files/03-05/nginx-hostpath-demo.yaml)
(下方保留带注释版本便于学习;执行时请优先使用真源文件):
```yaml
apiVersion: apps/v1 # Deployment 所属 API 版本
@@ -199,8 +208,8 @@ spec: # Service 规格
应用与最小验证:
```bash
# 1) 保存上面的 YAML 到 /tmp/nginx-hostpath-demo.yaml 后应用
kubectl apply -f /tmp/nginx-hostpath-demo.yaml
# 1) 直接使用仓库真源应用
kubectl apply -f ansible/files/03-05/nginx-hostpath-demo.yaml
# 2) 等待就绪
kubectl rollout status deploy/nginx-hostpath-demo --timeout=180s
@@ -250,3 +259,8 @@ kubectl run curl-test --image=curlimages/curl:8.8.0 --restart=Never -it --rm --
- `03-06-k3s-使用nfs存储.md`(多节点共享目录)
- `03-07-k3s-longhorn-持久化存储.md`(重状态、快照、备份)
## 排障
- **先看 playbook 输出**:失败时先定位是 deploy/wait/http_check 哪一步。
- **集群侧总览**`kubectl get nodes -o wide``kubectl -n kube-system get pods -o wide`
- **事件与日志**`kubectl -n <ns> describe ...``kubectl -n <ns> logs ... --tail=200`