Files
k3s/009-基础设施/004-longhorn/readme.md
2026-02-05 00:11:05 +08:00

130 lines
3.9 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.
Installation Summary:
✅ Namespace created: longhorn-system
✅ S3 Secret created: longhorn-crypto with MinIO credentials
✅ Helm deployment: Longhorn v1 deployed successfully
✅ Components starting:
- longhorn-manager: Running (2/2)
- longhorn-ui: Running (2 replicas)
- longhorn-driver-deployer: Initializing
S3 Configuration Verified:
- AWS_ACCESS_KEY_ID: admin ✓
- AWS_SECRET_ACCESS_KEY: adminks.. ✓
- AWS_ENDPOINTS: https://s3.u6.net3w.com ✓
Next Steps:
The Longhorn components are still initializing. It will take a few minutes for all components (CSI drivers, Engine Images, Instance Managers) to be fully ready.
You can monitor the progress with:
kubectl get pods -n longhorn-system -w
这是一个非常棒的习惯!在生产实践中,这被称为 **IaC (基础设施即代码)**。即使我们使用 Helm 远程安装,也应该在本地保留一份“配置清单”,以便日后维护、迁移或重建集群。
为了满足你的需求,建议在 `/home/fei/k3s/009-基础设施/` 下创建两个标准化的文件夹。
---
## 1. 推荐的目录结构
你可以执行以下命令创建目录:
```bash
mkdir -p /home/fei/k3s/009-基础设施/003-helm
mkdir -p /home/fei/k3s/009-基础设施/004-longhorn
```
结构如下:
* **003-helm**: 存放 Helm 的安装脚本、环境变量配置。
* **004-longhorn**: 存放 Longhorn 的自定义配置文件(`values.yaml`)和 S3 密钥配置。
---
## 2. 文件夹内应该放什么内容?
### 文件夹003-helm
由于 Helm 是一个工具,这个文件夹主要存放**安装记录**和**环境配置**。
* **创建文件:`install_helm.sh**` (记录你是怎么装的)
```bash
# 写入以下内容
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
# 记录 K3s 环境变量
echo "export KUBECONFIG=/etc/rancher/k3s/k3s.yaml" >> ~/.bashrc
```
* **创建文件:`readme.md**`: 写明当前 Helm 的版本和用途。
---
### 文件夹004-longhorn
这是核心。虽然我们用远程仓库安装,但我们要把**配置参数**固化在本地。
**第一步:导出远程默认配置**
在文件夹下执行:
```bash
helm repo add longhorn https://charts.longhorn.io
helm repo update
helm show values longhorn/longhorn > values.yaml
```
现在,你拥有了一个几百行的 `values.yaml`,这就是 Longhorn 的“灵魂”。
**第二步:创建 S3 密钥文件 `s3-secret.yaml**`
因为你要对接 S3你需要把秘钥写成 K8s 的 Secret
```yaml
apiVersion: v1
kind: Secret
metadata:
name: longhorn-crypto
namespace: longhorn-system
type: Opaque
stringData:
AWS_ACCESS_KEY_ID: "你的ID"
AWS_SECRET_ACCESS_KEY: "你的密钥"
AWS_ENDPOINTS: "你的S3连接地址"
```
**第三步:创建一键安装脚本 `deploy.sh**`
```bash
# 1. 创建命名空间
kubectl create namespace longhorn-system
# 2. 应用 S3 密钥
kubectl apply -f s3-secret.yaml
# 3. 使用本地 values.yaml 安装远程仓库的应用
helm install longhorn longhorn/longhorn \
--namespace longhorn-system \
-f values.yaml
```
---
## 3. 这样做的好处
1. **版本可控**:以后你想改 S3 地址或副本数,只需要改 `/004-longhorn/values.yaml`,然后执行 `helm upgrade`。
2. **一目了然**:当你打开 `009-基础设施` 文件夹,你能清楚看到你的 S3、Helm 和 Longhorn 是如何相互关联的。
3. **快速重建**:如果哪天服务器系统重装了,你只需要进入这些文件夹,按顺序执行 `deploy.sh`,几分钟内整个基础设施就能起死回生。
---
## 4. 特别提示Redis 放在哪?
按照你的逻辑,你应该在 `009-基础设施` 之外(或者创建一个 `010-中间件` 文件夹)专门放 Redis 的 YAML。因为 Redis 是属于**应用层**,而 Longhorn 属于**存储层**。
**接下来,需要我帮你把上述的 `values.yaml` 中关于 S3 备份的关键配置项找出来,并告诉你如何修改吗?**