k8snode01 10.96.10.154
加载所需的内核模块
# cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
# modprobe overlay
# modprobe br_netfilter
修改内核参数
# cat <<EOF | sudo tee /etc/sysctl.d/99-k8s-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
# sysctl --system
关闭SWAP
# swapoff -a
# vi /etc/fstab
设置Ubuntu与CRI-O的版本号
# OS=xUbuntu_20.04
# VERSION=1.23
下载安装cri-o cri-o-runc cri-tools
# echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
# echo "deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list
# curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/Release.key | apt-key add -
# curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | apt-key add -
# apt-get update
# apt-get install cri-o cri-o-runc cri-tools
启动CRI-O
# systemctl enable --now crio
# systemctl start crio
下载安装Kubelet Kubeadm Kubectl
# curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
# echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
# apt-get update
# apt-get install -y kubelet kubeadm kubectl
# apt-mark hold kubelet kubeadm kubectl
初始化节点并配置pod-network-cidr
# kubeadm init --pod-network-cidr=10.244.0.0/16
为管理用户配置kubectl
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
使Master Node也可作为Worker Node
$ kubectl taint nodes --all node-role.kubernetes.io/master-
安装Calico Pod网络插件
# kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
# kubectl create -f https://docs.projectcalico.org/manifests/custom-resources.yaml
查看Node状态
$ kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8snode01.qlab.com Ready control-plane,master 5h49m v1.23.4 10.96.11.55 <none> Ubuntu 20.04.4 LTS 5.4.0-104-generic cri-o://1.22.2
查看Kubelet服务日志
# journalctl -xeu kubelet
重置Kubelet
尽力还原由 kubeadm init 或 kubeadm join 所做的更改
# kubeadm reset
https://kubernetes.io/zh/docs/reference/setup-tools/kubeadm/kubeadm-reset/
查看CRI-O状态
# crictl info