本文最后更新于 2024年5月16日。
说明
下面是我学习搭建k8s的记录,并没有成功,应为我的vps配置太低了。
仅供参考学习,真正部署参考官方文档。
官方文档
https://kubernetes.io/zh-cn/docs/home/
https://github.com/guangzhengli/k8s-tutorials
安装三个组件
设置镜像库
vi /etc/yum.repos.d/kubernetes.repo
内容如下
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
会下载失败
kubelet-1.28.2-0.x86_64: Cannot download, all mirrors were already tried without success
修改镜像地址
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
安装k8s的三个工具
sudo dnf install -y kubelet kubeadm kubectl
成功,可能是国外的vps应该用国外的镜像地址
已经安装好了三个组件:kubelet kubeadm kubectl
初始化的时候报错
执行master节点初始化的时候报错,有太多不符合项目,所以用不了k8s。
[root@racknerd-d17e8e volumes]# kubeadm init
[init] Using Kubernetes version: v1.28.2
[preflight] Running pre-flight checks
[WARNING Firewalld]: firewalld is active, please ensure ports [6443 10250] are open or your cluster may not function correctly
[WARNING Swap]: swap is enabled; production deployments should disable swap unless testing the NodeSwap feature gate of the kubelet
[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR NumCPU]: the number of available CPUs 1 is less than the required 2
[ERROR Mem]: the system RAM (771 MB) is less than the minimum 1700 MB
[ERROR CRI]: container runtime is not running: output: time="2023-09-17T05:08:55-05:00" level=fatal msg="validate service connection: CRI v1 runtime API is not implemented for endpoint \"unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.RuntimeService"
, error: exit status 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
这里面的内容提示了我的vps不符合安装k8s的条件。