安装指定版本的kubeadm
#apt update && apt -y install apt-transport-https software-properties-common
#curl -fsSL https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
#add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main"
#apt-get update
#apt-cache madison kubelet kubectl kubeadm |grep '1.22.7-00'
#apt install -y kubelet=1.27.6-00 kubectl=1.27.6-00 kubeadm=1.27.6-00
安装容器运行时
Add Docker's official GPG key:
#sudo apt-get update
#sudo apt-get -y install ca-certificates curl
#sudo install -m 0755 -d /etc/apt/keyrings
#sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
#sudo chmod a+r /etc/apt/keyrings/docker.asc
Add the repository to Apt sources:
#echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
#sudo apt-get update
install containerd
#apt -y install containerd.io
Configure containerd
生成默认配置
#mkdir -p /etc/containerd
#containerd config default > /etc/containerd/config.toml
配置 systemd cgroup 驱动
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
...
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
配置镜像加速
...
[plugins."io.containerd.grpc.v1.cri".registry]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.k8s.io"]
endpoint = ["https://k8s.nju.edu.cn"]
...
加载br_netfilter模块
#modprobe br_netfilter
#echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
修改内核配置
tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
加载配置
sysctl --system
配置cgroup驱动
#cat kubeadm-config.yaml
kind: ClusterConfiguration
apiVersion: kubeadm.k8s.io/v1beta3
kubernetesVersion: v1.27.0
---
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
cgroupDriver: systemd
##参考
https://v1-27.docs.kubernetes.io/zh-cn/docs/tasks/administer-cluster/kubeadm/configure-cgroup-driver/
kubeadm init
#kubeadm init --config kubeadm-config.yaml --pod-network-cidr=10.244.0.0/16
配置kube.config
#mkdir -p /root/.kube/
#cp -p /etc/kubernetes/admin.conf /root/.kube/config
deploy a pod network to the cluster
#kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
查看集群信息
#kubectl cluster-info
Kubernetes control plane is running at https://10.x.x.249:6443
CoreDNS is running at https://10.x.x.249:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.