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

同样,再加1个节点 10.10.10.122 node122

8,设置 calico BGP RR

参照 这个链接 https://blog.51cto.com/14143894/2463392?source=drh 做的
root@node122:/etc/cni/net.d# kubectl get node —show-labels
NAME STATUS ROLES AGE VERSION LABELS
node120 Ready master 12h v1.18.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node120,kubernetes.io/os=linux,node-role.kubernetes.io/master=
node121 Ready 12h v1.18.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node121,kubernetes.io/os=linux,route-reflector=true
node122 Ready 9h v1.18.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node122,kubernetes.io/os=linux

cat /etc/calico/calicoctl.cfg
apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
datastoreType: “kubernetes”
kubeconfig: “/root/.kube/config”

cat bgp_disable.yaml
apiVersion: projectcalico.org/v3
kind: BGPConfiguration
metadata:
name: default
spec:
logSeverityScreen: Info
nodeToNodeMeshEnabled: false
asNumber: 64512

apiVersion: projectcalico.org/v3
kind: Node
metadata:
annotations:
projectcalico.org/kube-labels: ‘{“beta.kubernetes.io/arch”:”amd64”,”beta.kubernetes.io/os”:”linux”,”kubernetes.io/arch”:”amd64”,”kubernetes.io/hostname”:”node121”,”kubernetes.io/os”:”linux”,”route-reflector”:”true”}’
creationTimestamp: “2020-12-06T15:29:03Z”
labels:
beta.kubernetes.io/arch: amd64
beta.kubernetes.io/os: linux
kubernetes.io/arch: amd64
kubernetes.io/hostname: node121
kubernetes.io/os: linux
route-reflector: “true”
name: node121
resourceVersion: “136548”
uid: a77e209d-a0f5-44c0-9c71-45e6a9a8d55a
spec:
addresses:
- address: 10.10.10.121/24
- address: 10.10.10.121
bgp:
ipv4Address: 10.10.10.121/24
routeReflectorClusterID: 244.0.0.1
orchRefs:
- nodeName: node121
orchestrator: k8s
status:
podCIDRs:
- 192.168.1.0/24

cat bgp1.yaml
apiVersion: projectcalico.org/v3
kind: BGPPeer
metadata:
name: peer-with-route-reflectors
spec:
nodeSelector: all() #所以的节点
peerSelector: route-reflector == ‘true’

最后一次执行这给 这3个文件 就可以了 ,得到的结果是这这样的
calicoctl get bgppeers
NAME PEERIP NODE ASN
peer-with-route-reflectors all() 0

calicoctl node status
Calico process is running.
IPv4 BGP status
+———————+———————-+———-+—————+——————-+
| PEER ADDRESS | PEER TYPE | STATE | SINCE | INFO |
+———————+———————-+———-+—————+——————-+
| 10.10.10.121 | node specific | up | 07:03:12 | Established |
+———————+———————-+———-+—————+——————-+
IPv6 BGP status
No IPv6 peers found.

9,其它

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