vi /etc/hostname
yum install -y yum-utils
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl start docker
参考:Install Docker Engine on CentOS | Docker Documentation
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubelet-1.22.4 kubeadm-1.22.4 kubectl-1.22.4 --disableexcludes=kubernetes
setenforce 0
echo '{"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"],"exec-opts": ["native.cgroupdriver=systemd"]}' > /etc/docker/daemon.json
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet
swapoff -a
kubeadm config print init-defaults > init.default.yaml
cp init.default.yaml init-config.yaml
在 init-config.yaml 中输入以下内容
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
imageRepository: registry.aliyuncs.com/google_containers
kubernetesVersion: 1.22.4
networking:
podSubnet: 192.168.0.0/16
kubeadm config images pull --config=init-config.yaml
docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.22.4 k8s.gcr.io/kube-apiserver:v1.22.4
docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.22.4 k8s.gcr.io/kube-controller-manager:v1.22.4
docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.22.4 k8s.gcr.io/kube-scheduler:v1.22.4
docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.22.4 k8s.gcr.io/kube-proxy:v1.22.4
docker tag registry.aliyuncs.com/google_containers/pause:3.5 k8s.gcr.io/pause:3.5
docker tag registry.aliyuncs.com/google_containers/etcd:3.5.0-0 k8s.gcr.io/etcd:3.5.0-0
docker tag registry.aliyuncs.com/google_containers/coredns:v1.8.4 k8s.gcr.io/coredns/coredns:v1.8.4
kubeadm init --config=init-config.yaml --ignore-preflight-errors=all
如果发生错误可使用 如下命令查看日志,并根据具体问题解决
journalctl -f -u kubelet
成功提示:
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
测试:
kubectl -n kube-system get configmap
kubeadm join 192.168.83.129:6443 --token 51e80a.o41mpmgj3db447ne \
--discovery-token-ca-cert-hash sha256:6a233ea8c4376baa23b77224fec33781f09798213ee3ddaf3fbee95f421f6786 \
--ignore-preflight-errors=all
kubectl apply -f "https://docs.projectcalico.org/manifests/calico.yaml"
或者先下载下来
wget https://docs.projectcalico.org/manifests/calico.yaml
再
kubectl apply -f calico.yaml
安装完成后等一会:再次查看状态
注意!这里可能有calico-kube-controllers或者coredns未启动或者运行报错,可能是网段原因导致的,步骤10的podSubnet
如果您的网络运行在192.168.x.x 请使用10.0.0.0/16
如果您的网络是10.0.x.x 请使用192.168.0.0/16
去除master的pod不能部署限制
kubectl taint nodes --all node-role.kubernetes.io/master-
# 下载flannel插件的yml
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# 修改kube-flannel.yml中的镜像仓库地址为国内源
sed -i 's/quay.io/quay-mirror.qiniu.com/g' kube-flannel.yml
# 修改kube-flannel.yml中
"Network": "10.0.0.0/16",
# 安装网络插件
kubectl apply -f kube-flannel.yml
#虚拟机重启后
systemctl start kubelet
setenforce 0
swapoff -a