文档说明:自建K8S,只记录关键地方;
k8s 版本 > 1.19
CRI 使用 containerd
实验环境: linux debian 11
#!/bin/bash
set -eux
set -o pipefail
# enp0s3 是网卡名称
KUBE_VERSION=`kubelet --version | awk -F ' ' '{print $2}'`
ip=$(ip address show | grep enp0s3 | grep 'inet' | awk '{print $2}' | awk -F '/' '{print $1}')
ip=$(ip -4 address show | grep enp0s3 | grep 'inet' | awk '{print $2}' | awk -F '/' '{print $1}' | sed -n '1p')
kubeadm config images list --v=5 --kubernetes-version=$(kubelet --version | awk -F ' ' '{print $2}')
kubeadm config images pull --v=5 --kubernetes-version=$(kubelet --version | awk -F ' ' '{print $2}')
swapoff -a
# 看看有什么报错,就解决什么报错即可 --v=5 显示日志的级别
kubeadm init --dry-run --v=5 --kubernetes-version=$KUBE_VERSION
kubeadm config images list
kubeadm config images pull
# 开始初始化
ip=$(ip address show | grep enp0s3 | grep 'inet' | awk '{print $2}' | awk -F '/' '{print $1}')
kubeadm init \
--kubernetes-version=$(kubelet --version | awk -F ' ' '{print $2}') \
--pod-network-cidr=10.244.0.0/16,fd00:11::/64 \
--service-cidr=10.96.0.0/16,fd00:22::/112 \
--token-ttl 0 \
--v=5 \
--apiserver-advertise-address="${ip}"
mkdir -p $HOME/.kube
echo "y\n" | cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
kubenetes 使用ipvs 替代 iptables
kubectl edit configmap kube-proxy -n kube-system
# change mode from "" to ipvs
# mode: ipvs
确认是否cgroup是否是systemd
kubectl edit cm kubelet-config -n kube-system
cgroupDriver: systemd