学习 Kubernetes(二):Minikube

安装

假设你已经安装了 VirtualBox。使用 Homebrew 安装 Minikube:

brew cask install minikube  

启动

使用国内 Docker 镜像(阿里云):

minikube start --image-mirror-country cn  

使用指定 Kubernetes 版本:

minikube start --kubernetes-version v1.14.3  

本地 kubectl 切换到 minikube 上下文:

kubectl config set-context minikube  

操作

启动 Dashboard:

minikube dashboard  

SSH 登录虚拟机:

minikube ssh  

停止虚拟机:

minikube stop  

配置私有 Register

SSH 登录虚拟机:

minikube ssh  

编辑 /usr/lib/systemd/system/docker.service 文件:

ExecStart=  
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=virtualbox  
ExecReload=/bin/kill -s HUP  

在 ExecStart 末尾添加:

--insecure-registry <Registry 地址>

重启 Docker Daemon 服务:

systemctl stop docker  
systemctl daemon-reload  
systemctl start docker  

Trouble Shooting

下载 ISO 文件失败

报错信息:

💣  Failed to cache ISO
❌  Error:         [ISO_DOWNLOAD_FAILED] https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso: failed to download: failed to download to temp file: failed to create validator: failed to create validator: failed to download checksum file: Get https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso.sha256: read tcp 10.18.0.242:56742->172.217.160.112:443: read: connection reset by peer
💡  Advice:        A firewall is likely blocking minikube from reaching the internet. You may need to configure minikube to use a proxy.
📘  Documentation: https://github.com/kubernetes/minikube/blob/master/docs/http_proxy.md
⁉️   Related issues:
    ▪ https://github.com/kubernetes/minikube/issues/3922

解决方案:

下载镜像到本地,拷贝到 ~/.minikube/cache/iso 目录下。

下载地址:

  • minikube-v1.2.0.iso(百度云盘,提取码:zh5r);
  • minikube-v1.3.0.iso(百度云盘,提取码:jgw8)。

下载 kubeadm/kubelet 失败

报错信息:

💣  Failed to update cluster: downloading binaries: downloading kubeadm: Error downloading kubeadm v1.14.3: failed to download: failed to download to temp file: download failed: 5 error(s) occurred:

* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.14.3/bin/linux/amd64/kubeadm: dial tcp 172.217.160.112:443: i/o timeout
* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.14.3/bin/linux/amd64/kubeadm: dial tcp 172.217.160.112:443: i/o timeout
* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.14.3/bin/linux/amd64/kubeadm: dial tcp 172.217.160.112:443: i/o timeout
* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.14.3/bin/linux/amd64/kubeadm: dial tcp 172.217.160.112:443: i/o timeout
* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.14.3/bin/linux/amd64/kubeadm: dial tcp 172.217.160.112:443: i/o timeout

下载 kubeadm 和 kubelet 到本地,拷贝到 ~/.minikube/cache/<版本> 目录下。

下载地址:

启动 Dashboard 报错

报错信息:

💣  http://127.0.0.1:54999/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/ is not responding properly: Temporary Error: unexpected response code: 503
Temporary Error: unexpected response code: 503  

解决方案:

根据 minikube dashboard returns 503 error on macOS 的答案,删除 minikube:

minikube delete -p minikube  

重启启动,好了。

重启大法好!👍

参考