Skip to content

Commit a6b3ecc

Browse files
committed
更新k8s搭建
1 parent 6938897 commit a6b3ecc

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

_posts/2023-07-30-k8s-init.md

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,26 @@ title: k8s服务初始化记录
77

88
[官方安装地址](https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/install-kubeadm/)
99

10-
1. 设置自动完成
10+
2. 设置自动完成
1111

1212

1313
```bash
1414
kubeadm completion bash > /etc/bash_completion.d/kubeadm
1515
kubectl completion bash > /etc/bash_completion.d/kubectl
16-
1716
```
1817

18+
3. [镜像服务器设置](https://www.geekery.cn/free-service/docker-hub-mirror.html)
19+
20+
```/etc/docker/daemon.json
21+
{
22+
"registry-mirrors": [
23+
"https://hub.geekery.cn/",
24+
"https://ghcr.geekery.cn"
25+
]
26+
}
27+
```
1928

20-
1. 修改 containerd 默认设置
29+
4. 修改 containerd 默认设置
2130

2231
`containerd config default > /etc/containerd/config.toml`
2332

@@ -29,19 +38,9 @@ kubectl completion bash > /etc/bash_completion.d/kubectl
2938

3039
设置完成后重启 `systemctl restart containerd`
3140

32-
2. 下载网络插件镜像 [flannel仓库](https://github.com/flannel-io/flannel)
33-
34-
下面命令使用的镜像, 可以自己下载
3541

36-
```
37-
PREFIX=m.daocloud.io/
38-
for x in docker.io/flannel/flannel:v0.22.1 docker.io/flannel/flannel-cni-plugin:v1.2.0; do
39-
echo $x
40-
crictl pull $PREFIX$x
41-
done
42-
```
4342

44-
3. 执行k8s初始化, IP根据下一步中的配置文件(kube-flannel.yml)中的`net-conf.json.NetWork`而定 [IP说明](https://github.com/flannel-io/flannel/blob/master/Documentation/kubernetes.md)
43+
5. 执行k8s初始化, IP根据下一步中的配置文件(kube-flannel.yml)中的`net-conf.json.NetWork`而定 [IP说明](https://github.com/flannel-io/flannel/blob/master/Documentation/kubernetes.md)
4544

4645
可选步骤, 提前拉取k8s用的镜像
4746

@@ -66,7 +65,21 @@ kubectl completion bash > /etc/bash_completion.d/kubectl
6665
初始化集群
6766
`kubeadm init --pod-network-cidr 10.244.0.0/16`
6867
69-
4. 安装网络插件
68+
6. 下载网络插件镜像 [flannel仓库](https://github.com/flannel-io/flannel)
69+
70+
下面命令使用的镜像, 可以自己下载, 版本根据 `kube-flannel.yml` 而定
71+
72+
```
73+
for x in docker.io/flannel/flannel:v0.26.1 docker.io/flannel/flannel-cni-plugin:v1.5.1-flannel2; do
74+
echo $x
75+
docker pull $x
76+
docker save $x | ctr --namespace k8s.io images import -
77+
done
78+
```
79+
80+
7. 安装网络插件
81+
82+
开启内核模块 `modprobe br_netfilter`
7083
7184
`kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml`
7285
@@ -82,22 +95,22 @@ kubectl completion bash > /etc/bash_completion.d/kubectl
8295
- /opt/bin/flanneld
8396
```
8497
85-
5. 根据上一步命令的结果, 设置配置文件
98+
8. 根据上一步命令的结果, 设置配置文件
8699
87100
```
88101
mkdir -p $HOME/.kube
89102
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
90103
sudo chown $(id -u):$(id -g) $HOME/.kube/config
91104
```
92105
93-
6. 查看结果 `kubectl get nodes`
106+
9. 查看结果 `kubectl get nodes`
94107
95-
7. 防火墙和端口 [文档](https://kubernetes.io/zh-cn/docs/reference/networking/ports-and-protocols/)
108+
10. 防火墙和端口 [文档](https://kubernetes.io/zh-cn/docs/reference/networking/ports-and-protocols/)
96109
97110
要么直接关闭, 要么把上述端口加到防火墙. 要不然 coredns pod启动不了.
98111
99-
8. 注意关闭交换分区
112+
11. 注意关闭交换分区
100113
101114
`swapoff --all`
102115
103-
9. 安装网络插件[calico](https://docs.tigera.io/calico/latest/getting-started/kubernetes/quickstart)
116+
12. 安装网络插件[calico](https://docs.tigera.io/calico/latest/getting-started/kubernetes/quickstart)

0 commit comments

Comments
 (0)