Minikube安装成功Kubernetes,一次过!

介绍

Minikube 是 K8S 官方为了开发者能在个人电脑上运行 K8S 而提供的一套工具。实现上是通过 Go 语言编写,通过调用虚拟化管理程序,创建出一个运行在虚拟机内的单节点集群。

注:从这里也可以看出,对于 K8S 集群的基本功能而言,节点数并没有什么限制。只有一个节点同样可以创建集群。

大家在实际开发和体验 Kubernetes时,可能会遇到网络访问的原因或者其他的坑导致很多朋友无法使用minikube进行实验。因此我通过撰写这篇博客,让大家少走一点弯路。阿里云提供了一个修改版的Minikube,可以从阿里云的镜像地址来获取Docker镜像和配置。

坑位盘点

  1. unable to cache ISO: connection failed because connected host has failed to respond.

    终端报错信息:

    minikube start
    
    o   minikube v0.35.0 on windows (amd64)
    >   Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
    @   Downloading Minikube ISO ...
    !   Unable to start VM: unable to cache ISO: https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: failed to download: failed to download to temp file: download failed: 5 error(s) occurred
    :
    
    * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no
    t properly respond after a period of time, or established connection failed because connected host has failed to respond.
    * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no
    t properly respond after a period of time, or established connection failed because connected host has failed to respond.
    * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no
    t properly respond after a period of time, or established connection failed because connected host has failed to respond.
    * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no
    t properly respond after a period of time, or established connection failed because connected host has failed to respond.
    * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no
    t properly respond after a period of time, or established connection failed because connected host has failed to respond.

    报错原因: 由于无法从外网下载Minikube ISO出现如上报错。

    解决办法: 修改镜像地址为国内资源,解决网络错误。

  2. Minikube doesn‘t run on VirtualBox

    终端报错信息:

    minikube start
    
    ?? minikube v1.0.1 on linux (amd64) ?? Downloading Kubernetes v1.14.1 images in the background ... ?? Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
    
    ?? Unable to start VM: create: creating: Unable to start the VM: /usr/bin/VBoxManage startvm minikube --type headless failed: VBoxManage: error: The virtual machine 'minikube' has terminated unexpectedly during startup with exit code 1 (0x1) VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine
    
    ?? Sorry that minikube crashed. If this was unexpected, we would love to hear from you: ?? https://github.com/kubernetes/minikube/issues/new

    报错原因: VT-x/AMD-v虚拟化在所有CPU中被禁用。

    解决方法: VT-x/AMD-v虚拟化必须在BIOS中开启。

    参考文档: https://jingyan.baidu.com/article/fc07f98976710e12ffe519de.html

  3. [MACHINE_DOES_NOT_EXST] Error getting state for host: machine does not exist

    终端报错信息

    [sudo] james 的密码:
    ??  minikube v1.2.0 on linux (amd64)
    ??  Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.
    ?  using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
    ??  Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
    E0722 14:57:51.637843    5215 start.go:559] StartHost: Error getting state for host: machine does not exist
    
    ??  Unable to start VM
    ?  Error:         [MACHINE_DOES_NOT_EXST] Error getting state for host: machine does not exist
    ??  Advice:        Run 'minikube delete' to delete the stale VM
    ??   Related issues:
        ? https://github.com/kubernetes/minikube/issues/3864
    
    ??  If the above advice does not help, please let us know:
    ??  https://github.com/kubernetes/minikube/issues/new
    

    报错原因: 已经被使用过VM

    解决办法: minikute delete

注:

  • 本文已更新到 Minikube v1.2.0/Kubernetes v1.15+
  • 如需更新minikube,需要更新 minikube 安装包
    • minikube delete 删除现有虚机,删除 ~/.minikube 目录缓存的文件
    • 重新创建 minikube 环境
  • Docker社区版也为Mac/Windows用户提供了Kubernetes开发环境的支持 https://yq.aliyun.com/articles/508460,大家也可以试用

配置

先决条件

Minikube在不同操作系统上支持不同的驱动

  • macOS

  • Linux
    • VirtualBoxKVM
    • NOTE: Minikube 也支持 --vm-driver=none 选项来在本机运行 Kubernetes 组件,这时候需要本机安装了 Docker。在使用 0.27版本之前的 none 驱动时,在执行 minikube delete 命令时,会移除 /data 目录,请注意,问题说明;另外 none 驱动会运行一个不安全的API Server,会导致安全隐患,不建议在个人工作环境安装。
  • Windows

注:

  • 由于minikube复用了docker-machine,在其软件包中已经支持了相应的VirtualBox, VMware Fusion驱动
  • VT-x/AMD-v 虚拟化必须在 BIOS 中开启
  • 在Windows环境下,如果开启了Hyper-V,不支持VirtualBox方式

Kubernetes 1.14+ release

我们提供了最新的Minikube修改版的文件,可以直接下载使用

Mac OSX

curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.2.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

Linux

curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.2.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

Windows

下载 minikube-windows-amd64.exe 文件,并重命名为 minikube.exe

自己构建

也可以从Github上获取相应的项目自行构建。

注:需要本地已经安装配置好 Golang 开发环境和Docker引擎

git clone https://github.com/AliyunContainerService/minikube
cd minikube
git checkout aliyun-v1.2.0
make
sudo cp out/minikube /usr/local/bin/

启动

缺省Minikube使用VirtualBox驱动来创建Kubernetes本地环境

minikube start --registry-mirror=https://registry.docker-cn.com

??  minikube v1.2.0 on linux (amd64)
??  Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.
?  using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
??  Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
??  Configuring environment for Kubernetes v1.15.0 on Docker 18.09.6
??  Pulling images ...
??  Launching Kubernetes ...
?  Verifying: apiserver proxy etcd scheduler controller dns
??  Done! kubectl is now configured to use "minikube"

支持不同的Kubernetes版本

# 安装Kubernetes v1.12.1
minikube start --registry-mirror=https://registry.docker-cn.com --kubernetes-version v1.12.1

打开Kubernetes控制台

minikube dashboard

对于使用Hyper-V环境的用户,首先应该打开Hyper-V管理器创建一个外部虚拟交换机,

之后,我们可以用如下命令来创建基于Hyper-V的Kubernetes测试环境

.\minikube.exe start --registry-mirror=https://registry.docker-cn.com --vm-driver="hyperv" --memory=4096 --hyperv-virtual-switch="MinikubeSwitch"

注:需要管理员权限来创建Hyper-V虚拟机

Minikube基本操作

检测集群状态,运行:

 kubectl cluster-info

 Kubernetes master is running at https://192.168.99.100:8443
KubeDNS is running at https://192.168.99.100:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Ubuntu下,Minikube的配置文件在如下路径

~/.minikube/machines/minikube/config.json

查看配置文件内容:

kubectl config view

apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/james/.minikube/ca.crt
    server: https://192.168.99.100:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /home/james/.minikube/client.crt
    client-key: /home/james/.minikube/client.key

检验Node状态:

kubectl get nodes

NAME       STATUS   ROLES    AGE   VERSION
minikube   Ready    master   11m   v1.15.0

使用ssh进入Minikube虚机:

sudo minikube ssh
                         _             _
            _         _ ( )           ( )
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

$

停止运行中的kubernetes集群:

$ minikube stop

删除本地的kubernetes集群:

$ minikube delete

打开Kubernetes控制台

Kubernete附带一个web,允许您在不与命令行交互的情况下管理集群。在minikube上默认安装并启用仪表板插件

$ minikube addons list

- addon-manager: enabled
- coredns: disabled
- dashboard: enabled
- default-storageclass: enabled
- efk: disabled
- freshpod: disabled
- heapster: disabled
- ingress: disabled
- kube-dns: enabled
- metrics-server: disabled
- registry: disabled
- registry-creds: disabled
- storage-provisioner: enabled

要直接在默认浏览器上打开,请使用:

$ minikube dashboard

获取仪表板的URL

$ minikube dashboard --url
http://192.168.39.117:30000

通过打开您最喜欢的浏览器上的URL访问Kubernetes Dashboard。进一步阅读,请查看:

  • 你好Minikube系列: https://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/
  • minkube新手指南: https://kubernetes.io/docs/getting-started-guides/minikube/

使用Minikube

Minikube利用本地虚拟机环境部署Kubernetes,其基本架构如下图所示。

用户使用Minikube CLI管理虚拟机上的Kubernetes环境,比如:启动,停止,删除,获取状态等。一旦Minikube虚拟机启动,用户就可以使用熟悉的Kubectl CLI在Kubernetes集群上执行操作。

好了,开始探索Kubernetes的世界吧!:-)

参考连接:

  • https://computingforgeeks.com/how-to-install-minikube-on-ubuntu-18-04/
  • https://www.virtualbox.org/wiki/Linux_Downloads
  • https://github.com/kubernetes/minikube/issues/3922
  • https://stackoverflow.com/questions/55988282/minikube-doesnt-run-on-virtualbox
  • https://github.com/AliyunContainerService/minikube/releases
  • https://yq.aliyun.com/articles/221687
  • https://jingyan.baidu.com/article/fc07f98976710e12ffe519de.html
  • https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
  • https://github.com/kubernetes/minikube/issues/3864

原文地址:https://www.cnblogs.com/sanshengshui/p/11228985.html

时间: 2024-07-30 13:04:12

Minikube安装成功Kubernetes,一次过!的相关文章

HP LaserJet P1007 驱动安装成功,但无法打印的原因

HP LaserJet P1007 打印机驱动安装成功,但是无法打印相关文档的原因是: 打印机是水货,惠普中国提供的驱动和该打印机不符合.显示的应该是HP LaserJet Professional P1007,而且还要安装EWS驱动,所以安装国内的驱动是无法正确支持的.应该安装HP LaserJet Professional P1007的驱动才能正常打印.驱动保存在百度云中,以作备份.

mongodb 怎样检测 安装成功

mongodb 主页 http://www.mongodb.org/ 1.先在网上下载一个mongodb的安装包,再打开cmd命令,找到你装mongodb的文件的路径,进到mongodb的文件下的lib文件下,最后再在cmd命令下执行 mongod.exe --dbpath d:\mongodbData(你新建的文件夹,mongodb文件夹是一个存放数据文件,路径是d:\mongodbData) mongod.exe  服务器  运行该执行文件可以设置mongodb的端口号,数据文件存储目录等

安装成功edx后,通过ip地址访问出现登录验证框的问题

主要是在playbooks中设置了登录验证. 修改 cd /var/tmp/configuration/playbooks/roles/common/defaults sudo vi main.yml COMMON_ENABLE_BASIC_AUTH: True 将其改为 False,保存. 然后再进行安装. cd /var/tmp/configuration/playbooks && sudo ansible-playbook -c local ./edx_sandbox.yml -i

超详细的php安装过程保证安装成功

PHP安装必要条件====>需要先成功安装mysql 检查安装PHP需要的编译库: yum  install  -y  zlib-devel libxml2-devel libjpeg-turbo-devel  libiconv-devel yum  install  -y  freetype-devel  libpng-devel  gd-devel  libcurl-devel 检查安装包是否安装完成: rpm  -qa  zlib-devel libxml2-devel libjpeg-t

elementary os 0.4.1下编译GCC-7.1源码并安装成功

参考文章:http://www.2cto.com/os/201402/281131.html 前几天为了图个新鲜,安装了elementary os 0.4.1,的确是一股清流,可惜的是gcc版本觉得有点老了点,这不刚刚gcc 7.1也出来了,就想试试,特记录如下: 准备必要的系统环境:(升级系统到最新,安装必要的工具) sudo apt-get update                             #升级系统到最新 sudo apt-get install gcc g++ gaw

vm装xp安装成功后进入不了系统

1.如果是用虚拟光驱,你肯定步骤是先新建的虚拟机,再安装的虚拟光驱,所以会出现这样的问题.(请先安装虚拟光驱,再新建虚拟机,再用虚拟光驱加载镜像文件,问题解决)2.如果是直接使用的镜像,那么在GHOST系后,回出现这样的问题,解决方法:GHOST后,选择不使用镜像.3.如果在自定义安装中新建虚拟机的时候没有立即分配磁盘空间(也就是那项你没有打勾) ,请你删除你现在的虚拟机,重新新建,一定要记得 将 立即分配磁盘空间 打钩 4.磁盘分区时,设置一个主磁盘为活动或者作用本人在装xp时经常碰到3,4问

eclipse 插件未安装成功定位

以gef未安装成功为例 在eclipse根目录下: eclipse –clean –console –noExit 右击窗口标题栏,属性,勾中快速编辑模式,这样可以在命令行窗口点击右键将剪贴板上的内容粘贴到命令行窗口中 执行命令: ss org.eclipse.gef 没有结果,表示gef没有安装成功 使用命令安装: install file:dropins/GEF-Update-3.10.0/plugins/org.eclipse.gef_3.10.0.201506010206.jar 文件夹

oracle11g静默安装----&gt;静默安装成功后,导入失败解决【四】

通过以上几篇文章,静默安装成功,做数据导出expdp,没有任何问题!如果做Impdp导入会报错,下面给出了解决方法!! 使用expdp/impdp工具报错: ORA-39006: internal error ORA-39213: Metadata processing is not available Cause: The Data Pump could not use the Metadata API. Typically, this is caused by the XSL stylesh

CentOS7 + Win7 双系统完美运行安装成功 不需要bcd引导

因为准备学习linux开发,所以要在老机器上安装centos7 win7双系统,我的老机器是500G HDD 划分了360g 给win7 200g 给Centos.网上关于双系统的安装纷繁复杂,而且大多数有误导也无法行得通,我通过看了好多篇总算安装成功了,并且没有使用大量文章中提到的BCD软件做引导,直接修改GRUB2下面的配置文件就搞定了,十分的轻松写意. 1.安装win7不说了,从安装centos7开始,首先下载了ISO文件以后,很多文章提到要使用UltraISO把光盘镜像刷入到U盘里是不行