synchronization

This commit is contained in:
2025-08-25 17:53:08 +08:00
commit c201eb5ef9
318 changed files with 23092 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
> 本文作者:丁辉
# Flannel网络不通容器
## 一:缺失路由导致无法通讯
1. 查看路由
```bash
route -n
```
2. 添加路由
```bash
route add -net 10.0.0.0 netmask 255.255.0.0 dev flannel0
```
> 添加路由后,需要重启 flannal 服务
**其他操作**
> 主机处于192.168.10.0/24而想访问192.168.20.0/24网的主机可以这样配置路由。
- 添加默认网关
```bash
route add -net 192.168.20.0 netmask 255.255.255.0 gw 192.168.10.1
```
- 删除默认网关
```bash
route del -net 192.168.20.0 netmask 255.255.255.0
```

View File

@@ -0,0 +1,63 @@
> 本文作者:丁辉
# Jumpserver-helm部署时遇到的问题
[jumpserver官网地址](https://docs.jumpserver.org/zh/master/install/setup_by_fast/?h=labels)
- 组件启动一直处于准备状态未启动 (原因是因为有一个 Svc 没有生成出来导致其他 Pod 无法连接)
(这个问题有点久远了,当时写这份文档的时候没有截图报错哈哈)
1. 部署 service
```bash
vi jump-svc.yaml
```
内容如下
```yaml
apiVersion: v1
kind: Service
metadata:
name: jump-service
spec:
selector:
app.jumpserver.org/name: jms-web
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30000
type: NodePort
```
2. 部署
```bash
kubectl apply -f jump-svc.yaml
```
- Jumpsevrer-helm部署遇到解析未自动生成问题
单独给pod添加域名解析
- 写法1
```yaml
hostAliases:
- ip: 127.0.0.1
hostnames:
- "$yuming"
```
- 写法2
```yaml
hostAliases:
- hostnames:
- $yuming
ip: 127.0.0.1
```

View File

@@ -0,0 +1,18 @@
> 本文作者:丁辉
# K3s-Helm部署报错
报错内容为
```bash
Error: INSTALLATION FAILED: Kubernetes cluster unreachable: Get "http://localhost:8080/version": dial tcp [::1]:8080: connect: connection refused
```
> 问题原因:本地没有 kube-config 导致 K3s 无法连接到 Kubernetes 集群引起的
执行命令解决
```bash
kubectl config view --raw > ~/.kube/config
```

View File

@@ -0,0 +1,81 @@
> 本文作者:丁辉
# Kubeadm安装K8s失败记录
- 在我部署 k8s 的时候,最近会遇到 flannel 一直重启的情况(报错 pod cidr not assigne
```bash
vim /etc/kubernetes/manifests/kube-controller-manager.yaml
```
```bash
- --allocate-node-cidrs=true
- --cluster-cidr=10.244.0.0/16
```
```bash
systemctl restart kubelet
```
- k8s-kubeadm单节点搭建导致主节点污点禁止pod运行
```bash
#查看污点
kubectl describe nodes master | grep -A 3 Taints
#删除
kubectl taint nodes <node> <taints>-
#一次删除多个
kubectl taint nodes --all node-role.kubernetes.io/control-plane- node-role.kubernetes.io/master-
```
- k8s-kubeadm-containerd搭建网络通讯问题
```bash
vim /etc/kubernetes/manifests/kube-controller-manager.yaml
增加参数:
- --allocate-node-cidrs=true
- --cluster-cidr=10.244.0.0/16
systemctl restart kubelet
```
- K8s "tab" 报错
```bash
yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
```
- 安装 K8s 失败,发现缺少一下模块
1. 添加模块
```bash
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack
EOF
```
2. 加载
```bash
modprobe br_netfilter
lsmod | grep netfilter
sysctl -p /etc/sysctl.d/k8s.conf
sysctl --system
```
3. 替换镜像源
```bash
sed -i 's#sandbox_image = "k8s.gcr.io/pause:3.6"#sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.6"#' /etc/containerd/config.toml
```

View File

@@ -0,0 +1,29 @@
> 本文作者:丁辉
# Kubernetes容器启动报打开的文件数过多
**failed to create fsnotify watcher: too many open files**
> 系统中打开文件数目过多,导致无法创建更多的文件监视器
- 临时
```bash
sysctl -w fs.inotify.max_user_instances=2099999999
```
- 永久
```bash
echo "fs.inotify.max_user_instances = 2099999999" >> /etc/sysctl.conf
sysctl -p
```
重启容器后恢复
> 清理慎用
>
> ```bash
> lsof | awk '{print $2}' | sort | uniq -c | sort -n | awk '{if ($1 > threshold) print $2}' | xargs -I{} kill {}
> ```

View File

@@ -0,0 +1,78 @@
> 本文作者:丁辉
# Rke部署K8s报错
- Rke 部署的时候报错Failed to set up SSH tunneling for host
> 解决办法
1. 改动一下 SSH 参数
```bash
vim /etc/ssh/sshd_config
```
2. 修改此参数
```bash
AllowTcpForwarding yes
```
- RKE部署 K8s 其中 Nginx-proxy 容器缺失配置文件
> 在初始化 RKE 的时候报错可能会是说检测失败
问题原因是因为 Nginx-proxy arm 版 docker 镜像有问题,导致 Nginx 配置文件内容不正确,替换一下内容即可修复
1. 编辑配置文件
```bash
vi nginx.conf
```
内容如下
```nginx
error_log stderr notice;
worker_processes auto;
events {
multi_accept on;
use epoll;
worker_connections 1024;
}
stream {
upstream kube_apiserver {
server 10.206.16.12:6443;
}
server {
listen 6443;
proxy_pass kube_apiserver;
proxy_timeout 10m;
proxy_connect_timeout 2s;
}
}
```
2. 拷贝配置文件到容器内
```bash
docker cp nginx.conf nginx-proxy:/etc/nginx/nginx.conf
```
3. 重启容器
```bash
docker restart nginx-proxy
```

View File

@@ -0,0 +1,72 @@
> 本文作者:丁辉
# 本地无法访问Service网络
## 添加路由
> 引发问题场景:
>
> - 一主机多网卡情况下
> - 缺失路由导致无法通讯或主机默认路由网段错误
| 主机网关 | 是否为 Kubernetes 使用网络 |
| :-----------: | :------------------------: |
| 192.168.1.100 | 是 |
| 192.168.2.100 | 否 |
1. 查看默认路由
```bash
ip route show default
```
> 查看路由基础命令
>
> - 查看路由
>
> ```bash
> route -n
> ```
>
> - 查看路由
>
> ```bash
> ip route
> ```
2. 添加默认路由
```bash
route add default gw 192.168.1.100 dev eth0
```
> 或使用 `ip route` 命令
>
> ```
> ip route add default via 192.168.1.100 dev eth0
> ```
3. 刷新路由缓存
```bash
ip route flush cache
```
4. 添加路由后,需要重启 Kubernetes 网络插件
## 遇到问题
> 如果已存在默认路由呢?
**删除默认路由**
```bash
route del default gw 192.168.2.100 dev eth0
```
```bash
ip route del default via 192.168.2.100 dev eth0
```