feat: init commit
This commit is contained in:
BIN
images/image1.png
Normal file
BIN
images/image1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
BIN
images/image2.png
Normal file
BIN
images/image2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
51
nfs系统创建指南.md
Normal file
51
nfs系统创建指南.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# nfs系统创建指南
|
||||
意在创建一个可共享、跨节点可用的存储系统,供k3s、kubernetes使用的文件系统
|
||||
|
||||
**安装nfs-kernel**
|
||||
|
||||
```
|
||||
sudo apt update
|
||||
sudo apt install -y nfs-kernel-server
|
||||
```
|
||||
|
||||
**创建共享目录**
|
||||
|
||||
```
|
||||
mkdir -p /data/nfs
|
||||
//编辑权限,测试使用777,生产环境可以换成特定uid
|
||||
chmod -R 777 /data/nfs
|
||||
```
|
||||
|
||||
**编辑配置文件**
|
||||
向/etc/exports文件中追加以下内容
|
||||
|
||||
```
|
||||
/data/nfs 10.42.0.0/16(rw,sync,no_subtree_check,no_root_squash)
|
||||
```
|
||||
|
||||
参数解释:
|
||||
|
||||
rw:允许读写;
|
||||
|
||||
sync:数据同步写入磁盘;
|
||||
|
||||
no_subtree_check:关闭子树检查,提高性能;
|
||||
|
||||
no_root_squash:允许 root 用户访问;
|
||||
|
||||
10.42.0.0/16 是 k3s 默认 Pod 网络(可按实际调整)。
|
||||
|
||||
tips: 10.42.0.0/16是k3s所有pod的内部所在网段(对于集群所在宿主机而言)
|
||||
|
||||
|
||||
**应用配置并启动服务**
|
||||
```
|
||||
sudo exportfs -ra
|
||||
sudo systemctl enable nfs-server --now
|
||||
```
|
||||
|
||||
**确认服务状态**
|
||||
```
|
||||
sudo systemctl status nfs-server
|
||||
```
|
||||
|
||||
77
rke2集群搭建指南.md
Normal file
77
rke2集群搭建指南.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# rke2集群搭建指南
|
||||
rke2仅支持单宿主机单节点,否则会出现一堆问题
|
||||
|
||||
|
||||
**前期准备**
|
||||
根据官方文档,进行kubectl工具安装
|
||||
依次执行:
|
||||
```
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
|
||||
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check //验证输出是否为ok,判断文件下载是否有误
|
||||
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl //安装kubectl
|
||||
```
|
||||
安装完成后,可以执行kubectl version --client 查看当前版本
|
||||
|
||||
根据官方文档,进行rke2的安装
|
||||
执行:
|
||||
```
|
||||
curl -sfL https://get.rke2.io | sh -
|
||||
```
|
||||
国外链接安装需要挂梯子,建议使用国内下载链接
|
||||
```
|
||||
curl -sfL https://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn sh -
|
||||
```
|
||||
|
||||
#### 关键
|
||||
|
||||
**如果你需要使用非localhost访问集群kubernetes api,需要添加--tls-san {machine.ip}**
|
||||
我是这样操作的:
|
||||
首先运行
|
||||
```
|
||||
systemctl enable rke2-server
|
||||
```
|
||||
不出意外,应该会输出service文件位置,例如我的:
|
||||

|
||||
|
||||
使用nano打开,找到execstart命令组的rke2 server
|
||||
追加内容 --tls-san {machine.ip}
|
||||
例如这样:
|
||||

|
||||
保存退出
|
||||
|
||||
**关于镜像拉取**
|
||||
个人认为躲不掉,配置以下环境变量的事情
|
||||
根据.service文件可以得知,systemd启动rke2-server时会读取以下目录的环境变量:
|
||||
EnvironmentFile=-/etc/default/%N
|
||||
EnvironmentFile=-/etc/sysconfig/%N
|
||||
EnvironmentFile=-/usr/local/lib/systemd/system/%N.env
|
||||
|
||||
%N为服务名
|
||||
|
||||
于是可以直接创建环境变量文件,这里我选择了nano /etc/sysconfig/rke2-server(文件夹可能提示不存在,创建一个即可)
|
||||
添加如下内容:
|
||||
```
|
||||
HTTP_PROXY=http://127.0.0.1:7897
|
||||
HTTPS_PROXY=http://127.0.0.1:7897
|
||||
NO_PROXY=127.0.0.1,localhost,10.0.0.0/8,192.168.0.0/16
|
||||
```
|
||||
10.0.0.0/8的设置是因为我的隧道也是10.0.0.0/24,所以放宽了规则,避免隧道流量走代理
|
||||
|
||||
到这里,配置就基本上完成了,最后记得执行
|
||||
```
|
||||
sudo systemctl daemon-reload
|
||||
```
|
||||
|
||||
|
||||
**运行**
|
||||
执行命令
|
||||
```
|
||||
systemctl start rke2-server
|
||||
```
|
||||
|
||||
等待一段时间,成功后在/etc/rancher/rke2目录下有rke2.yaml,这个文件相当于集群最高管理员的密钥
|
||||
可以直接使用rke2自带的kubectl,也可以用全局的;
|
||||
全局的话有两个办法:一个是全局变量的形式,另一个是直接创建或追加集群、用户内容到~/.kube/config
|
||||
|
||||
至此,rke2集群便可以正常运行了
|
||||
8
ssh公私钥配置.md
Normal file
8
ssh公私钥配置.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# 配置ssh密钥快速指南
|
||||
配置密钥可以实现快速登录就是了
|
||||
|
||||
运行监听tls证书的脚本pod,会初始化ssh公私钥
|
||||
将公钥复制到被连接服务器对应用户的.ssh/authorized_key里面保存
|
||||
|
||||
**重点**
|
||||
需要进入该pod手动进行一次ssh连接,目的是接受并保存指纹信息,脚本自动监听并没有这个机制,但是这是必须的
|
||||
68
利用scp和ssh实现中转服务器证书配置自动同步.md
Normal file
68
利用scp和ssh实现中转服务器证书配置自动同步.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# 利用scp和ssh实现中转服务器证书配置自动同步
|
||||
|
||||
**背景**
|
||||
博主使用的架构是
|
||||
用户-->中转服务器nginx反代-->wireguard-->rke2集群网关nginx
|
||||
|
||||
因为有中转,tls握手需要在nginx实现一次;
|
||||
因为有wireguard(自己会加密),所以tls可以终止与中转服务器nginx;
|
||||
|
||||
通过搜索资料得知,这样也可以实现自动化,利用scp和ssh,创建一个pod监听tls证书生成
|
||||
|
||||
然后分成nginx需要的pem和key,连同server配置块一同上传到中转服务器
|
||||
|
||||
scp需要登录用户对文件夹有写入权限,这一点有时候比较难注意到
|
||||
因此推荐使用sudo tee的方式,这样可以在服务器配置该用户sudo某些指令不需要使用密码,ssh连接使用bash,更加方便
|
||||
|
||||
|
||||
**操作**
|
||||
使用预先创建的ssh密钥或者让pod自己生成ssh密钥
|
||||
|
||||
自己创建的密钥,打包进入容器后记得设置权限(私钥600,公钥644),否则ssh-server不会使用
|
||||
上传例如这样:
|
||||
```
|
||||
ssh_command = [
|
||||
"ssh", f"{NGINX_USER}@{NGINX_HOST}",
|
||||
f"sudo tee {remote_file} > /dev/null"
|
||||
]
|
||||
```
|
||||
|
||||
编写好脚本后在服务器运行,我使用tls-sync.yaml创建了一个pod,为了使pod有权限监听全部命名空间,需要创建一个serviceAccount并绑定pod
|
||||
```
|
||||
# serviceaccount.yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: secret-watcher
|
||||
namespace: basic
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: secret-watcher-role
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["secrets"]
|
||||
verbs: ["get", "list", "watch"]
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: secret-watcher-binding
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: secret-watcher-role
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: secret-watcher
|
||||
namespace: basic
|
||||
|
||||
```
|
||||
namespace替换成pod运行的位置
|
||||
|
||||
使用kubectl apply应用serviceaccount.yaml和tls-sync.yaml
|
||||
|
||||
确保pod正常运行后,及时将ssh密钥处理好,然后进入容器手动进行一次ssh连接以信任并保存指纹
|
||||
|
||||
至此,监听程序正常运行
|
||||
37
远程节点加入指南.md
Normal file
37
远程节点加入指南.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# 基于本地k3d创建的集群的远程节点加入操作指南
|
||||
|
||||
**准备工作**
|
||||
|
||||
1、远程节点主机安装k3s
|
||||
|
||||
```
|
||||
curl -sfL https://get.k3s.io | sh -
|
||||
```
|
||||
|
||||
-sfl可以不要
|
||||
|
||||
2、获取节点密钥node-token
|
||||
|
||||
一般k3d任意节点都有,建议server节点查看
|
||||
|
||||
在/var/lib/rancher/k3s/server/node-token
|
||||
|
||||
|
||||
|
||||
**执行命令**
|
||||
|
||||
```
|
||||
curl -sfL https://get.k3s.io | K3S_URL=https://<api-server-ip>:6443 K3S_TOKEN='<your-token>' sh -s - agent --node-name <node-name>
|
||||
```
|
||||
|
||||
等待执行结束,k3s-agent服务启动成功即可
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
tips:
|
||||
|
||||
执行命令这一步大概率需要梯子,如果该节点主机自己配置了vpn,那就再终端export一下就好
|
||||
|
||||
如果没有的话,参考”利用反向隧穿使用宿主机vpn“
|
||||
Reference in New Issue
Block a user