Files
Deploy-Laboratory/docs/02-01-nginx-control-ingress.md
2026-03-29 09:08:01 +08:00

59 lines
1.8 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.
# 02-01 Nginx + 控制节点 + IngressM1
> 场景nginx 落在控制节点(`nodeSelector: node-role.kubernetes.io/control-plane`),使用标准 Ingress 暴露 `/demo-m1`。整合于 `02-05-nginx-验证矩阵-一键部署.md`。
## TL;DR
- **手动练习**:以本课清单 `ansible/files/02-01/01-control-ingress.yaml` 复制到目标机,按本文改字段后执行下方 `kubectl`/bash学习路径可不使用 verify
- **自动化验收**`./ansible/bin/verify.sh run 02-01`
- **你需要准备**:入口节点 `:80` 可达;(可选)`nginx_entry_base=http://<入口IP>` 用于脚本侧 HTTP 校验
- **成功判据**`/demo-m1/` 返回 `200` 且能区分后端(见本篇“验证命令/预期”与 playbook 断言)
- **排障**:见本文「排障」
## 前置条件
- 已完成 `01-02-k3s-工作节点.md`
- 控制节点有 `node-role.kubernetes.io/control-plane` 标签
- 入口节点 80 可达
## 操作步骤
1. 部署 nginx DeploymentnodeSelector 控制节点)+ Service
2. 创建 Middleware + Ingress`/demo-m1` -> nginx-m1:80
3. 等待 Pod 与 Ingress 就绪
示例 YAML 见 `ansible/files/02-01/01-control-ingress.yaml`
## 部署命令
```bash
kubectl apply -f ansible/files/02-01/01-control-ingress.yaml
```
## 验证命令
```bash
kubectl get pod,svc,ing -n default -o wide
curl -i --max-time 3 http://<入口节点IP>/demo-m1/
```
## 预期
- 返回 200页面包含 Welcome to nginx!
- Pod 落在控制节点(`kubectl get pod -o wide` 的 NODE 列为控制节点)
## 删除
```bash
kubectl delete -f ansible/files/02-01/01-control-ingress.yaml
```
## 排障
- 确认 Traefik 接管 Ingress、Service/Endpoint 正常
- 参考 `06-01-k3s-networkpolicy-故障排查.md`
## 下一步
- 返回 `02-05-nginx-验证矩阵-一键部署.md``00-00-构建总览.md`