步骤
机器:4核8G,root账号,可访问互联网
1、更新apt apt-get update
2、安装一些基本工具 apt-get install ca-certificates curl gnupg lsb-release net-tools apt-transport-https
3、ifconfig
获取ip,hostname
获取主机名,若主机名不符合规范(比如有特殊字符,则使用hostnamectl set-hostname <hostname>
修改)
4、更新hosts echo "<ip> <hostname>" >> /etc/hosts
5、mkdir -m 0755 -p /etc/apt/keyrings
6、装证书curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
7、声明软件源echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
7、更新aptapt-get update
8、安装docker和containerdapt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
9、此时docker命令可用,crictl还不行
10、准备安装kubeadmcurl -fsSL https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/k8s.gpg
11、echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/k8s.gpg] https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list > /dev/null
12、更新aptapt-get update
13、安装kubeadm apt-get install -y kubelet=1.26.1-00 kubeadm=1.26.1-00 kubectl=1.26.1-00
14、apt-mark hold kubelet kubeadm kubectl
15、vi /etc/crictl.yaml
编辑crictl配置,文件内容如下:
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false
16、containerd使用配置。containerd config default > /etc/containerd/config.toml
17、修改containerd默认配置:
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"
SystemdCgroup = true
18、重启服务 systemctl restart containerd
19、禁用交换分区swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab
20、编辑kubeadm启动文件,vi kubeadm.yaml
apiServer:
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: 1.26.0
networking:
dnsDomain: cluster.local
serviceSubnet: 10.96.0.0/12
scheduler: {}
21.启动kubeadmkubeadm init --config kubeadm.yaml
参考文档
1、安装docker和containerd:https://docs.docker.com/engine/install/ubuntu/
2、安装kubeadm:https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/install-kubeadm/