Linux安装minikube指南

2019-07-02 11:11:58 浏览数 (1)

版权声明:欢迎转载,请注明出处,谢谢。 https://blog.csdn.net/boling_cavalry/article/details/91304127

在linux安装minikube时遇到两个问题,在此记录整个安装过程,希望能够给遇见同样问题的读者一些参考;

前提

本次部署实战需要先解决谷歌镜像的下载问题,请确保您的网络可以正常访问和下载这些资源;

环境信息

  1. 操作系统:CentOS Linux release 7.6.1810
  2. Docker:1.13.1

准备工作

在安装minikube之前,要先对电脑做些设置,例如swap、防火墙、selinux等,这些操作的步骤和细节请参照《CentOS7环境部署kubenetes1.12版本五部曲之一:标准化机器》

完成基本设置就可以正式开始了;

设置Docker

部署的第一步是对修改docker的cgroup driver设置,使其和即将安装的kubelet服务保持一致,否则会导致kubelet启动失败:

  1. 打开文件/usr/lib/systemd/system/docker.service,如下图,将红框中的systemd改为cgroupfs:
  1. 重新加载配置信息,重启服务:
代码语言:javascript复制
systemctl daemon-reload && systemctl restart docker

安装kubectl

  1. 下载kubectl文件:
代码语言:javascript复制
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  1. 赋可执行权限:
代码语言:javascript复制
chmod  x ./kubectl
  1. 移动到系统目录:
代码语言:javascript复制
sudo mv ./kubectl /usr/local/bin/kubectl
  1. 现在可以在任意位置执行kubectl命令了:
代码语言:javascript复制
[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有以下两种运行方式:

  1. 运行在虚拟机,这要求当前电脑上要先安装VirtualBox或者KVM;
  2. 运行在宿主机,这种方式不需要在当前电脑安装ViirtualBox或者KVM;

为了快速安装,今天实战用到的是上面的第二种方式;

  1. 下载最新版minikube,并赋予可执行权限:
代码语言:javascript复制
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 
  && chmod  x minikube
  1. 移动到系统目录,以便在任意位置可以执行minikube命令:
代码语言:javascript复制
sudo cp minikube /usr/local/bin && rm minikube
  1. 启动minikube,参数–vm-driver=none表示minikube运行在宿主机,不需要提前安装VirtualBox或者KVM:
代码语言:javascript复制
minikube start --vm-driver=none

等待一段时间后(和下载镜像的速度有关),minikube启动成功,执行kubectl get services查看服务正常:

代码语言:javascript复制
[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:
  - https://github.com/kubernetes/minikube/blob/master/docs/vmdriver-none.md

! kubectl and minikube configuration will be stored in /root
! To use kubectl or minikube commands as your own user, you may
! need to relocate them. For example, to overwrite your own settings:

  - sudo mv /root/.kube /root/.minikube $HOME
  - sudo chown -R $USER $HOME/.kube $HOME/.minikube

* This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
* Verifying: apiserver proxy etcd scheduler controller dns
* Done! kubectl is now configured to use "minikube"
[root@minikubeblog ~]# kubectl get services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   7m10s

至此,Linux环境部署和启动minikube成功,希望本文能给你在部署minikube时提供一些参考。

0 人点赞