Skip to content

Commit bfe7a6d

Browse files
committed
更新 k3s-cilium
- 修复安装过程中的问题 - 使用 Native 路由
1 parent 223c308 commit bfe7a6d

File tree

2 files changed

+75
-43
lines changed

2 files changed

+75
-43
lines changed

src/SUMMARY.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
[MyLog - 我的经验与记录](README.md)
44
- [搞运维](linux/README.md)
5+
- [K8s](linux/Kubernetes/README.md)
6+
- [权限与用户](linux/Kubernetes/权限与用户.md)
7+
- [OKG(OpenKruiseGame)](linux/Kubernetes/OpenKruiseGame.md)
8+
- [在k3s中安装cilium并使用eBPF路由](linux/Kubernetes/20251130-在k3s中安装cilium并使用eBPF路由.md)
59
- [Nginx充当镜像源](linux/日常使用/20251027-Nginx充当镜像源.md)
610
- [解决Wayland下Plasmashell经常卡死的问题](linux/日常使用/20251027-Wayland-Plasmashell-Nvidia.md)
711
- [SSH Config 常用配置翻译](linux/日常使用/SSH常用配置项.md)
@@ -18,10 +22,6 @@
1822
- [Zabbix + ElasticSearch + ilm 解决方案](linux/Observability/zabbix_elastic_ilm.md)
1923
- [Prometheus备忘录](linux/Observability/Prometheus备忘录.md)
2024
- [Mimir备忘录](linux/Observability/Mimir备忘录.md)
21-
- [K8s](linux/Kubernetes/README.md)
22-
- [权限与用户](linux/Kubernetes/权限与用户.md)
23-
- [OKG(OpenKruiseGame)](linux/Kubernetes/OpenKruiseGame.md)
24-
- [在k3s中安装cilium并使用eBPF路由](linux/Kubernetes/20251130-在k3s中安装cilium并使用eBPF路由.md)
2525
- [NAS的一些记录](HomeNetwork/NAS/README.md)
2626
- [群晖](HomeNetwork/NAS/DSM/README.md)
2727
- [改群晖DSM的默认端口](HomeNetwork/NAS/DSM/ChangeSynologyNginxPoint.md)

src/linux/Kubernetes/20251130-在k3s中安装cilium并使用eBPF路由.md

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
go version go1.24.9
66
> * debian 13.2 (trixie)
77
6.12.57+deb13-amd64
8+
> * Cilium
9+
v1.18.4
810

911
- [安装 k3s 集群](#安装-k3s-集群)
1012
- [安装 Cilium](#安装-cilium)
@@ -15,10 +17,10 @@
1517

1618
根据 [K3s 安装选项介绍][k3s/install-options][K3s Server 配置参考][k3s/server-config][Cilium 安装文档][install-cilium] 得来
1719
```sh
18-
TOKEN=`dd if=/dev/urandom bs=4M count=1 | md5sum | xargs printf "%s\n" | head -1`
1920
ARGS=(
2021
--write-kubeconfig-mode=0644
2122
--flannel-backend=none
23+
--prefer-bundled-bin
2224
--disable-network-policy
2325
--disable-kube-proxy
2426
--disable-cloud-controller
@@ -28,33 +30,37 @@ ARGS=(
2830
--disable=metrics-server
2931
--disable=local-storage
3032
)
31-
echo $TOKEN
33+
TOKEN=`dd if=/dev/urandom bs=4M count=1 | md5sum | xargs printf "%s\n" | head -1`
34+
printf 'TOKEN=%s\n' $TOKEN
35+
36+
# 先下载安装脚本(对我就是一个apt包也不装)
37+
wget https://get.k3s.io -O /tmp/getk3s.sh
3238

3339
# 第一个节点
34-
curl -sfL https://get.k3s.io | K3S_TOKEN=${TOKEN}\
35-
INSTALL_K3S_EXEC="${ARGS[@]}"\
40+
env K3S_TOKEN=${TOKEN}\
41+
INSTALL_K3S_EXEC="${ARGS[*]}"\
3642
INSTALL_K3S_CHANNEL=v1.32\
37-
sh - --cluster-init
43+
sh /tmp/getk3s.sh --cluster-init
3844

3945
# 其他控制平面节点
40-
curl -sfL https://get.k3s.io | K3S_TOKEN=${TOKEN}\
41-
INSTALL_K3S_EXEC="${ARGS[@]}"\
46+
env K3S_TOKEN=${TOKEN}\
47+
INSTALL_K3S_EXEC="${ARGS[*]}"\
4248
INSTALL_K3S_CHANNEL=v1.32\
43-
sh - --server https://${第一个节点IP}:6443
49+
sh /tmp/getk3s.sh --server https://${第一个节点IP}:6443
4450

4551
# Agent节点
46-
curl -sfL https://get.k3s.io | K3S_TOKEN=${TOKEN}\
47-
INSTALL_K3S_EXEC="${ARGS[@]}"\
52+
env K3S_TOKEN=${TOKEN}\
53+
INSTALL_K3S_EXEC="${ARGS[*]}"\
4854
INSTALL_K3S_CHANNEL=v1.32\
4955
K3S_URL=https://${第一个节点IP}:6443\
50-
sh -
56+
sh /tmp/getk3s.sh
5157
```
5258

53-
安装完成后除了第一个节点以外,其他节点都是`NotReady`,这是正常现象,毕竟现在没有网络
59+
安装完成后所有节点都是`NotReady`,这是正常现象,毕竟现在没有网络
5460

5561
| NAME | STATUS | ROLES | AGE | VERSION |
5662
| :---- | :------- | :------------------------ | :--- | :------------ |
57-
| k3s-1 | Ready | control-plane,etcd,master | 1h | v1.32.10+k3s1 |
63+
| k3s-1 | NotReady | control-plane,etcd,master | 1h | v1.32.10+k3s1 |
5864
| k3s-2 | NotReady | control-plane,etcd,master | 1h | v1.32.10+k3s1 |
5965
| k3s-3 | NotReady | control-plane,etcd,master | 1h | v1.32.10+k3s1 |
6066

@@ -65,39 +71,55 @@ curl -sfL https://get.k3s.io | K3S_TOKEN=${TOKEN}\
6571
2. 配置仓库
6672
```sh
6773
helm repo add cilium https://helm.cilium.io/
74+
# 获取版本
75+
helm search repo cilium
6876
```
6977
3. 安装 Cilium
7078
```sh
71-
helm install cilium cilium/cilium --version 1.18\
72-
--namespace kube-system\
73-
--set k8sServiceHost=${第一个节点IP}\
74-
--set k8sServicePort=6443\
75-
--set ipam.operator.clusterPoolIPv4PodCIDRList="10.42.0.0/16"\
76-
--set bpf.datapathMode=netkit\
77-
--set bpf.masquerade=true\
78-
--set bpf.distributedLRU.enabled=true\
79-
--set bpf.mapDynamicSizeRatio=0.08\
80-
--set ipv4.enabled=true\
81-
--set enableIPv4BIGTCP=true\
82-
--set kubeProxyReplacement=true\
83-
--set bpfClockProbe=true
79+
helm install cilium cilium/cilium --version 1.18.4\
80+
--set k8sServiceHost=${第一个节点IP}\
81+
--set k8sServicePort=6443\
82+
--set ipam.operator.clusterPoolIPv4PodCIDRList=10.42.0.0/16\
83+
--set bpf.datapathMode=netkit\
84+
--set bpf.masquerade=true\
85+
--set bpf.distributedLRU.enabled=true\
86+
--set bpf.mapDynamicSizeRatio=0.08\
87+
--set ipv4.enabled=true\
88+
--set enableIPv4BIGTCP=true\
89+
--set kubeProxyReplacement=true\
90+
--set bpfClockProbe=true\
91+
--set routingMode=native\
92+
--set autoDirectNodeRoutes=true\
93+
--set ipv4NativeRoutingCIDR=10.42.0.0/16\
94+
--set envoy.enabled=false\
95+
--set socketLB.enabled=true
8496
```
8597

8698
每一项的作用
8799

88-
| 项目 | 作用 |
89-
| :----------------------------------------- | :---------------------------------------------------------------- |
90-
| `k8sServiceHost` | 指定 K8s API 服务地址 |
91-
| `k8sServicePort` | 指定 K8s API 服务端口 |
92-
| `ipam.operator.clusterPoolIPv4PodCIDRList` | 设定集群的Pod地址池与K3s配置一致 |
93-
| `bpf.datapathMode=netkit` | 使用 [netkit](https://www.netkit.org/) 网卡<br/>需要Kernel >= 6.8 |
94-
| `bpf.masquerade` | 使用 eBPF 来做 NAT |
95-
| `bpf.distributedLRU.enabled` | 启用分布式 LRU 后端内存 |
96-
| `bpf.mapDynamicSizeRatio` | 设定动态映射内存百分比 |
97-
| `ipv4.enabled` | 启用IPv4 |
98-
| `enableIPv4BIGTCP` | 开启IPv4高吞吐能力 |
99-
| `kubeProxyReplacement` | 替代 kube-proxy |
100-
| `bpfClockProbe` | 启用 eBPF 时钟源探测 |
100+
| 项目 || 作用 |
101+
| :----------------------------------------- | :------------------------ | :----------------------------------------------------------------------------------------------- |
102+
| `k8sServiceHost` | `172.21.1.1` | 指定 K8s API 服务地址 |
103+
| `k8sServicePort` | `6443` | 指定 K8s API 服务端口 |
104+
| `ipam.operator.clusterPoolIPv4PodCIDRList` | `10.42.0.0/16` | 设定集群的Pod地址池与K3s配置一致 |
105+
| `bpf.datapathMode` | `netkit` | 使用 [netkit](https://www.netkit.org/) 网卡<br/>需要Kernel >= 6.8 |
106+
| `bpf.masquerade` | `true` | 使用 eBPF 来做 NAT |
107+
| `bpf.distributedLRU.enabled` | `true` | 启用分布式 LRU 后端内存 |
108+
| `bpf.mapDynamicSizeRatio` | `0.08` | 设定动态映射内存百分比 |
109+
| `ipv4.enabled` | `true` | 启用IPv4 |
110+
| `enableIPv4BIGTCP` | `true` | 启用高吞吐模式 |
111+
| `kubeProxyReplacement` | `true` | 替代 kube-proxy |
112+
| `bpfClockProbe` | `true` | 启用 eBPF 时钟源探测 |
113+
| `routingMode` | `native` | 使用节点原生路由模式处理流量 |
114+
| `ipv4NativeRoutingCIDR` | `10.42.0.0/16` | 指定可以进行路由的CIDR |
115+
| `autoDirectNodeRoutes` | `true` | 自动检测节点路由 |
116+
| `socketLB.enabled` | `true` | 启用 socketLB 劫持入流量 |
117+
| `envoy.enabled` | `false` | 禁用内嵌的envoy |
118+
| `image.repository` | `quay.io/cilium/cilium` | cilium的镜像(国内可以对这个地址做代理) |
119+
| `image.useDigest` | `false` | 不在镜像版本后面加上 digest 信息 |
120+
| `operator.image.repository` | `quay.io/cilium/operator` | cilium-operator的镜像(国内可以对这个地址做代理)<br/>需要两个镜像: operator 和 operator-generic |
121+
| `operator.image.useDigest` | `false` | 不在镜像版本后面加上 digest 信息 |
122+
101123
4. 等待完成
102124

103125
##
@@ -109,6 +131,16 @@ curl -sfL https://get.k3s.io | K3S_TOKEN=${TOKEN}\
109131
| k3s-2 | Ready | control-plane,etcd,master | 1h | v1.32.10+k3s1 |
110132
| k3s-3 | Ready | control-plane,etcd,master | 1h | v1.32.10+k3s1 |
111133

134+
可以验证网络是否正常
135+
136+
执行 `kubectl run --image alpine/kubectl -it --rm --wait --restart Never test --command /bin/sh`
137+
然后跑
138+
```sh
139+
nslookup kubernetes.default.svc.cluster.local
140+
nslookup kubernetes.default.svc.cluster.local ${其中一个coredns的IP}
141+
kubectl api-resources
142+
```
143+
是能出数据的
112144

113145
[k3s/install-options]: https://docs.rancher.cn/docs/k3s/installation/install-options/
114146
[k3s/server-config]: https://docs.rancher.cn/docs/k3s/installation/server-config/

0 commit comments

Comments
 (0)