Docker实践之K8S安装

关于安装K8S的方式很多,如:sealos,KubeSprayKopsRancherkubesphere等众多开源的组件,我们公司则是基于kubesphere来管理K8S集群,由于条件有限,这里就基于sealos搭建一个简单的1master 1nodeK8S集群。

基础准备

我们跟着官方的脚本走

  • 下载kubernetes离线包 wget -c https://sealyun.oss-cn-beijing.aliyuncs.com/05a3db657821277f5f3b92d834bbaf98-v1.23.1/kube1.23.1.tar.gz
  • 下载sealos工具包 wget -c https://sealyun.oss-cn-beijing.aliyuncs.com/latest/sealos && chmod +x sealos && mv sealos /usr/bin
  • 安装集群 `sealos init –passwd 123456

–master 192.168.0.2 –master 192.168.0.3 –master 192.168.0.4
–node 192.168.0.5
–pkg-url /root/kube1.22.0.tar.gz
–version v1.22.0`

上手实践


整个离线包足足有527M,我也很好奇,里面到底有些啥,解压后,可以看到里面只有一些kubernetes所需要的包,还有containerd及基础镜像文件,这个镜像就占了355M

先不管大小了,我们继续安装sealos命令工具,

我们执行sealos来测试是否安装成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[root@VM-12-3-centos ~]# sealos
A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.

Usage:
sealos [command]

Available Commands:
cert generate certs
clean Simplest way to clean your kubernets HA cluster
cloud sealos on cloud
cni A brief description of your command
completion Output shell completion code for the specified shell (bash or zsh)
config print config template to console
delete delete kubernetes apps installled by sealos..
etcd Simplest way to snapshot/restore your kubernets etcd
exec support exec cmd or copy file by Label/nodes
help Help about any command
init Simplest way to init your kubernets HA cluster
install install kubernetes apps, like dashboard prometheus ..
ipvs sealos create or care local ipvs lb
join Simplest way to join your kubernets HA cluster
route set default route gateway
upgrade upgrade your kubernetes version by sealos
version Print the version of sealos

Flags:
--config string config file (default is $HOME/.sealos/config.yaml)
-h, --help help for sealos
--info logger ture for Info, false for Debug

Use "sealos [command] --help" for more information about a command.

可以看到sealos安装已经安装成功,我继续去初始化集群

1
sealos init --passwd xxxxxxxx --master 101.34.179.216  --node 180.76.169.126 --pkg-url /root/kube1.22.0.tar.gz --version v1.22.0


根据官方的说安装并启动docker/containerd(1.20+安装containerd),已经安装了会重启docker/containerd. 高版本离线包自带docker/containerd,如没安装docker/containerd会自动安装,但是我这里已经安装Docker后,再执行sealos时会提示sealos install kubernetes version >= 1.20 use containerd cri instead,意思是说,kubernetes1.20+版本已经由containerd替代了Docker,最快速的解决方法便是卸载Docker,

1
2
3
yum -y remove docker-ce docker-cli-io containerd.io
rm -rf var /var/lib/docker

卸载后,再次运行集群初始化命令,这时候报另外一个错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[kubelet-check] Initial timeout of 40s passed.

Unfortunately, an error has occurred:
timed out waiting for the condition

This error is likely caused by:
- The kubelet is not running
- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)

If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
- 'systemctl status kubelet'
- 'journalctl -xeu kubelet'

Additionally, a control plane component may have crashed or exited when started by the container runtime.
To troubleshoot, list all containers using your preferred container runtimes CLI.

Here is one example how you may list all Kubernetes containers running in cri-o/containerd using crictl:
- 'crictl --runtime-endpoint /run/containerd/containerd.sock ps -a | grep kube | grep -v pause'
Once you have found the failing container, you can inspect its logs with:
- 'crictl --runtime-endpoint /run/containerd/containerd.sock logs CONTAINERID'

error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster
To see the stack trace of this error execute with --v=5 or higher

我用journalctl -r kubelet去看了一下日志,

发现一句modprobe: FATAL: Module nf_conntrack_ipv4 not found in directory /lib/modules/4.18.0-305.3.1.el8.x86_64,因为我的内核版本有些高,nf_conntrack_ipv4被nf_conntrack替换了,所以需要设置一下modprobe -- nf_conntrack,此时,端口10259(kube-cont)10257(kube-sche)已经占用,我们需要通过lsof -i tcp:10259去找到进程并杀掉,然后重新初始化

作者

eyiadmin

发布于

2022-01-07

更新于

2024-05-31

许可协议

评论