环境如下
ubunut20.04
master:192.168.17.66
worker:192.168.17.67
1.禁止swap分区
sudo vi /etc/fstab #注释掉swap一行
2.更改net.bridge.bridge-nf-call-iptables的值为1.(Ubuntu 20.04默认为1)
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
3.安装Docker
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docke
4.安装kubeadm、kubeadm、kubectl
sudo apt-get update
sudo apt-get install -y ca-certificates curl software-properties-common apt-transport-https curl
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
sudo tee /etc/apt/sources.list.d/kubernetes.list <<EOF
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
或者
sudo apt install -y kubeadm=1.20.8-00 kubelet=1.20.8-00 kubectl=1.20.8-00
sudo apt-mark hold kubelet kubeadm kubectl
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
5.初始化集群
在初始化之前这里有个镜像命名是有问题得
kubeadm拉取的镜像coredns标签多了一个v,实际是没有的v
我们先下载好不带v得coredns镜像,然后tag下
docker tag \
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.0\
registry.aliyuncs.com/google_containers/coredns:v1.8.0
kubeadm init \
--apiserver-advertise-address=192.168.17.66 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.20.8 \
--service-cidr=10.17.0.0/16 \
--pod-network-cidr=10.244.0.0/16 --v=5
# --service-cidr和--pod-network-cidr,必须不同网段,不能冲突
6.安装CNI(三种方案任选其一,这里我选得flannel)
#flannel,需要在kubeadm init 时设置 --pod-network-cidr=10.244.0.0/16
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
#weave
sysctl net.bridge.bridge-nf-call-iptables=1
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
#calico需要 kubeadm init 时设置 --pod-network-cidr=192.168.0.0/16
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/install
7.work节点加入集群
# 在node节点加入mater集群
kubeadm join 192.168.17.66:6443 \
--token jjyn5z.a2lsptd7fp535wg6 \
--discovery-token-ca-cert-hash \
sha256:042869a28916092dbf869b781d99bd8c056f908754493458225f5168a6520038