部署的第一步是对修改docker的cgroup driver设置,使其和即将安装的kubelet服务保持一致,否则会导致kubelet启动失败:
- 打开文件/usr/lib/systemd/system/docker.service,如下图,将红框中的systemd改为cgroupfs:
- 重新加载配置信息,重启服务:
systemctl daemon-reload && systemctl restart docker
安装kubectl
- 下载kubectl文件:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- 赋可执行权限:
chmod +x ./kubectl
- 移动到系统目录:
sudo mv ./kubectl /usr/local/bin/kubectl
- 现在可以在任意位置执行kubectl命令了:
[root@minikubeblog ~]# kubectl version
Client Version: version.Info{Major:“1”, Minor:“14”, GitVersion:“v1.14.2”, GitCommit:“66049e3b21efe110454d67df4fa62b08ea79a19b”, GitTreeState:“clean”, BuildDate:“2019-05-16T16:23:09Z”, GoVersion:“go1.12.5”, Compiler:“gc”, Platform:“linux/amd64”}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
从上述信息可见kubect已经可用,但是还连接不上server端,接下来我们就来安装和启动minikube;
安装minikube
minikube有以下两种运行方式:
- 运行在虚拟机,这要求当前电脑上要先安装VirtualBox或者KVM;
- 运行在宿主机,这种方式不需要在当前电脑安装ViirtualBox或者KVM;
为了快速安装,今天实战用到的是上面的第二种方式;
- 下载最新版minikube,并赋予可执行权限:
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
&& chmod +x minikube
- 移动到系统目录,以便在任意位置可以执行minikube命令:
sudo cp minikube /usr/local/bin && rm minikube
- 启动minikube,参数–vm-driver=none表示minikube运行在宿主机,不需要提前安装VirtualBox或者KVM:
minikube start --vm-driver=none
等待一段时间后(和下载镜像的速度有关),minikube启动成功,执行kubectl get services查看服务正常:
[root@minikubeblog ~]# minikube start --vm-driver=none
- minikube v1.1.1 on linux (amd64)
- Creating none VM (CPUs=2, Memory=2048MB, Disk=20000MB) …
- Configuring environment for Kubernetes v1.14.3 on Docker 1.13.1
- Unable to load cached images: loading cached images: loading image /root/.minikube/cache/images/gcr.io/k8s-minikube/storage-provisioner_v1.8.1: stat /root/.minikube/cache/images/gcr.io/k8s-minikube/storage-provisioner_v1.8.1: no such file or directory
- Downloading kubeadm v1.14.3
- Downloading kubelet v1.14.3
- Pulling images …
- Launching Kubernetes …
- Configuring local host environment …
! The ‘none’ driver provides limited isolation and may reduce system security and reliability.
! For more information, see:
最后的话
最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!
资料预览
给大家整理的视频资料:
给大家整理的电子书资料: