关闭所有的交换分区,如果需要回收磁盘资源,则可以使用swapoff关闭交换分区释放磁盘空间。
swapoff -a
为什么需要关闭swap?
kubernetes的设计是将实例紧密包装到尽可能接近100%。 所有的部署应该与CPU /内存限制固定在一起。 所以如果调度程序发送一个pod到一台机器,它不应该使用交换。 设计者不想交换,因为它会减慢速度。
在/etc/yum.repos.d/新建文件k8s.repo
name=Kubernetes
baseurl=http://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
yum install -y kubelet-1.21.0 kubeadm-1.21.0 kubectl-1.21.0
官网镜像由于网络问题,无法拉取,使用https://hub.docker.com/r/myifeng/k8s.gcr.io_kube-controller-manager 拉取镜像后tag 为官方镜像即可使用:
docker tag myifeng/k8s.gcr.io_kube-apiserver:v1.21.0 k8s.gcr.io/kube-apiserver:v1.21.0
docker tag myifeng/k8s.gcr.io_kube-proxy:v1.21.0 k8s.gcr.io/kube-proxy:v1.21.0
docker tag myifeng/k8s.gcr.io_kube-controller-manager::v1.21.0 k8s.gcr.io/kube-controller-manager:v1.21.0
docker tag myifeng/k8s.gcr.io_kube-scheduler:v1.21.0 k8s.gcr.io/kube-scheduler:v1.21.0
docker tag myifeng/k8s.gcr.io_pause:3.4.1 k8s.gcr.io/pause:3.4.1
docker tag myifeng/k8s.gcr.io_coredns:1.8.0 k8s.gcr.io/coredns/coredns:v1.8.0
docker tag myifeng/k8s.gcr.io_etcd:3.4.13-0 k8s.gcr.io/etcd:3.4.13-0
systemctl enable docker.service
systemctl start docker.service
systemctl enable kubelet.service
systemctl start kubelet.service
kubeadm init --kubernetes-version=v1.21.0
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml.
namespace/kube-flannel created
clusterrole.rbac.authorization.k8s.io/flannel configured
clusterrolebinding.rbac.authorization.k8s.io/flannel configured
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created
修改/etc/kubernetes/manifests/kube-controller-manager.yaml
spec:
containers:
- command:
- kube-controller-manager
- --authentication-kubeconfig=/etc/kubernetes/controller-manager.conf
- --authorization-kubeconfig=/etc/kubernetes/controller-manager.conf
- --bind-address=127.0.0.1
- --client-ca-file=/etc/kubernetes/pki/ca.crt
- --cluster-name=kubernetes
- --cluster-signing-cert-file=/etc/kubernetes/pki/ca.crt
- --cluster-signing-key-file=/etc/kubernetes/pki/ca.key
- --controllers=*,bootstrapsigner,tokencleaner
- --kubeconfig=/etc/kubernetes/controller-manager.conf
- --leader-elect=true
- --port=0
- --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
- --root-ca-file=/etc/kubernetes/pki/ca.crt
- --service-account-private-key-file=/etc/kubernetes/pki/sa.key
- --use-service-account-credentials=true
--allocate-node-cidrs=true # 添加
--cluster-cidr=10.244.0.0/16 # 添加 与kube-flannel.yml 中保持一致
查看node状态
kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
docker-ce011166091186.na131 Ready control-plane,master 67m v1.21.0 11.166.91.186 <none> Alibaba Group Enterprise Linux Server 7.2 (Paladin) 5.10.84-004.ali5000.alios7.x86_64 docker://18.9.9
参考文档:
1、https://www.cnblogs.com/effortsing/p/10014613.html
2、https://www.jianshu.com/p/a7dcb3d89944
3、https://blog.csdn.net/weixin_44602192/article/details/119379041
4、https://www.jianshu.com/p/d27141e18398