场景

听说Minikube中的k8s比docker中k8s更加接近真实环境,打算在本地安装一波minikube,官网地址如下:
https://minikube.sigs.k8s.io/docs/

步骤

现在本机的mac上面的docker中启用了k8s,先要禁用掉docker中k8s,并调小一下docker中的cpu和内存均为2(具体设置根据你的资源来配)。

安装kubectl

ALL_PROXY=socks5://127.0.0.1:7891 brew install kubectl

验证:

kubectl version --client
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-26T06:16:15Z", GoVersion:"go1.14", Compiler:"gc", Platform:"darwin/amd64"}

安装Hypervisor

ALL_PROXY=socks5://127.0.0.1:7891 brew install hyperkit
brew install docker-machine-driver-hyperkit

验证:

hyperkit -v
hyperkit: 0.20200224

Homepage: https://github.com/docker/hyperkit
License: BSD

安装minikube

ALL_PROXY=socks5://127.0.0.1:7891 brew install minikube

验证:

minikube version
minikube version: v1.9.2
commit: 93af9c1e43cab9618e301bc9fa720c63d5efa393

启动minikube

proxychains4 minikube start --cpus=4 --memory="6000mb"
proxychains] config file found: /usr/local/etc/proxychains.conf
[proxychains] preloading /usr/local/Cellar/proxychains-ng/4.14/lib/libproxychains4.dylib
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  storage.googleapis.com:443  ...  OK
😄  minikube v1.9.2 on Darwin 10.15.4
✨  Automatically selected the hyperkit driver

❗  'hyperkit' driver reported an issue: hyperkit version check failed:
parse date: parsing time "14" as "20060102": cannot parse "14" as "2006"
💡  Suggestion:
📘  Documentation: https://minikube.sigs.k8s.io/docs/reference/drivers/hyperkit/

💾  Downloading driver docker-machine-driver-hyperkit:
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  github.com:443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  github-production-release-asset-2e65be.s3.amazonaws.com:443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  github.com:443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  github-production-release-asset-2e65be.s3.amazonaws.com:443  ...  OK
    > docker-machine-driver-hyperkit.sha256: 65 B / 65 B [---] 100.00% ? p/s 0s
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  github.com:443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  github-production-release-asset-2e65be.s3.amazonaws.com:443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  github.com:443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  github-production-release-asset-2e65be.s3.amazonaws.com:443  ...  OK
    > docker-machine-driver-hyperkit: 10.90 MiB / 10.90 MiB  100.00% 4.92 MiB p
🔑  The 'hyperkit' driver requires elevated permissions. The following commands will be executed:

    $ sudo chown root:wheel /Users/zhangyalin/.minikube/bin/docker-machine-driver-hyperkit
    $ sudo chmod u+s /Users/zhangyalin/.minikube/bin/docker-machine-driver-hyperkit


Password:
💿  Downloading VM boot image ...
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  storage.googleapis.com:443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  storage.googleapis.com:443  ...  OK
    > minikube-v1.9.0.iso.sha256: 65 B / 65 B [--------------] 100.00% ? p/s 0s
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  storage.googleapis.com:443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  storage.googleapis.com:443  ...  OK
    > minikube-v1.9.0.iso: 174.93 MiB / 174.93 MiB [] 100.00% 10.78 MiB p/s 17s
👍  Starting control plane node m01 in cluster minikube
💾  Downloading Kubernetes v1.18.0 preload ...
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  storage.googleapis.com:443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  storage.googleapis.com:443  ...  OK
    > preloaded-images-k8s-v2-v1.18.0-docker-overlay2-amd64.tar.lz4: 542.91 MiB
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  www.googleapis.com:443  ...  OK
🔥  Creating hyperkit VM (CPUs=4, Memory=6000MB, Disk=20000MB) ...
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  127.0.0.1:60260  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
❗  This VM is having trouble accessing https://k8s.gcr.io
💡  To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
🐳  Preparing Kubernetes v1.18.0 on Docker 19.03.8 ...
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  127.0.0.1:60397  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
🌟  Enabling addons: default-storageclass, storage-provisioner
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  127.0.0.1:60420  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:8443  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  127.0.0.1:60427  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  127.0.0.1:60432  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  127.0.0.1:60439  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  127.0.0.1:60444  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:22  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:7891  ...  192.168.64.29:8443  ...  OK
🏄  Done! kubectl is now configured to use "minikube"

这里使用proxychains4对命令进行代理,这个过程中需要输入一次管理员密码,主要就是为了给安装好的软件进行授权;这个过程中有两个警告,第一个警告是对本地的hyperkit软件解析版本名发生了错误,这个可以忽略;第二个警告(开源软件内嵌谷歌云广告)是说虚拟机无法访问google云的k8s Docker 容器映像,这个其实也可以忽略,因为本地的docker中已经把k8s的映像pull好了。

验证minikube

查看状态命令:

minikube status

查看状态结果:

m01
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

查看当前配置:

kubectl config current-context

查看版本:

kubectl version

查看集群状态:

kubectl cluster-info

查看节点:

kubectl get no

打开dashboard:

minikube dashboard
🔌  Enabling dashboard ...
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  Opening http://127.0.0.1:60709/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...

效果:
minikube的dashboard
查看已经安装的addons:

minikube addons list
|-----------------------------|----------|--------------|
|         ADDON NAME          | PROFILE  |    STATUS    |
|-----------------------------|----------|--------------|
| dashboard                   | minikube | enabled ✅   |
| default-storageclass        | minikube | enabled ✅   |
| efk                         | minikube | disabled     |
| freshpod                    | minikube | disabled     |
| gvisor                      | minikube | disabled     |
| helm-tiller                 | minikube | disabled     |
| ingress                     | minikube | disabled     |
| ingress-dns                 | minikube | disabled     |
| istio                       | minikube | disabled     |
| istio-provisioner           | minikube | disabled     |
| logviewer                   | minikube | disabled     |
| metrics-server              | minikube | disabled     |
| nvidia-driver-installer     | minikube | disabled     |
| nvidia-gpu-device-plugin    | minikube | disabled     |
| registry                    | minikube | disabled     |
| registry-aliases            | minikube | disabled     |
| registry-creds              | minikube | disabled     |
| storage-provisioner         | minikube | enabled ✅   |
| storage-provisioner-gluster | minikube | disabled     |
|-----------------------------|----------|--------------|

总结

在启动的过程中,尝试过使用阿里云的镜像,具体命令如下:

minikube start --cpus=4 --memory="6000mb" --image-mirror-country="cn" --image-repository="registry.cn-hangzhou.aliyuncs.com/google_containers"

但是失败了,就改使用proxychains4来代理下载。

参考

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐