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 )
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`
1920ARGS=(
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}\
65712 . 配置仓库
6672 ``` sh
6773 helm repo add cilium https://helm.cilium.io/
74+ # 获取版本
75+ helm search repo cilium
6876 ```
69773 . 安装 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+
1011234 . 等待完成
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