1.禁用swap

swapoff -a
/etc/fstab里包含swap那一行注释掉

2.修改ubuntu系统镜像源:

把/etc/apt/sources.list文件修改成如下
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
然后执行
sudo apt-get update
sudo apt-get upgrade

3.安装docker

apt-get install -y docker.io
apt-get install -y vim

vim /etc/docker/daemon.json
{
“registry-mirrors”: [“https://alzgoonw.mirror.aliyuncs.com“],
“live-restore”: true
}
systemctl daemon-reload
systemctl restart docker
systemctl enable docker

vim /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
apt install curl
apt update && apt upgrade
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -

这里经常过不去,还需要安装
apt install -y gnupg2

4,安装kubeadm,kubeadm,kubeadm

apt-get install -y kubeadm=1.18.1-00 kubelet=1.18.1-00 kubeadm=1.18.1-00
apt-mark hold kubelet kubeadm kubectl
wget https://docs.projectcalico.org/manifests/calico.yaml

如果 使用BGP,就一定修改 CALICO_IPV$POOL_IPIP为Never
image.png

root@node121:~# cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 ubuntu
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
10.10.10.120 node120
10.10.10.121 node121

vim kubeadm-config.yaml

apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: 1.18.1 #<— Use the word stable for newest version
controlPlaneEndpoint: “node120:6443“ #<— Use the node alias not the IP
networking:
podSubnet: 192.168.0.0/16

我还因为 copy 过来多了字符,导致后面 不能执行

5. 拉镜像

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.18.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.18.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.18.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.7
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.18.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.18.1 k8s.gcr.io/kube-controller-manager:v1.18.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.18.1 k8s.gcr.io/kube-scheduler:v1.18.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.18.1 k8s.gcr.io/kube-proxy:v1.18.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2 k8s.gcr.io/pause:3.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.7 k8s.gcr.io/coredns:1.6.7
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.18.1 k8s.gcr.io/kube-apiserver:v1.18.1

6.初始化集群

kubeadm init —config=kubeadm-config.yaml —upload-certs | tee kubeadm-init.out

kubectl get nodes
cp /etc/kubernetes/admin.conf /root/.kube/config

kubectl apply -f calico.yaml
中间还因为 注释了192.168.0.0/16 两行 而出错,修正后继续

7.worknode同样步骤 (1-4步)

cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 ubuntu
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
10.10.10.120 node120
10.10.10.121 node121
ff02::1 ip6-allnodes

kubeadm join node120:6443 —token 6qivdr.y5sgkmf4mqbvjrjp —discovery-token-ca-cert-hash sha256:63bd8dc167040a8211e9e3e9c86e9e98b8b5e73783c9b90519dfc0745442c9af

8,其它

curl -O -L https://github.com/projectcalico/calicoctl/releases/download/v1.6.4/calicoctl (验证了这个比较坑,应该现在最新版本)
https://github.com/projectcalico/calicoctl/releases/download/v3.17.0/calicoctl-linux-amd64
或者看 https://github.com/projectcalico/calicoctl/releases