minikube 安裝過程附帶報錯解決辦法

minikube 安裝過程

clipboard.png

介紹

minikube

Minikube 是一個能夠在本地輕鬆運行 Kubernetes 的工具。Minikube 會在您的筆記本電腦中的虛擬機上運行一個單節點的 Kubernetes 集羣,以便用戶對 Kubernetes 進行試用或者在之上進行 Kubernetes 的平常開發。linux

kubectl

kubectl是用於針對Kubernetes集羣運行命令的命令行接口。git

安裝

環境

安裝環境:parallels 虛擬機
操做系統:centos 7 minimalgithub

過程

環境初始化

初始化所須要執行的命令,都是根據在安裝過程當中遇到的報錯,給出的解決辦法整理。web

# 安裝docker服務
sudo yum install docker

# 啓用docker服務
sudo systemctl enable docker.service

# 關閉防火牆
sudo systemctl stop firewalld

# 關閉內存交換
sudo swapoff -a

# 修改文件驅動
sudo vi /lib/systemd/system/docker.service
# 修改成cgroupfs
--exec-opt native.cgroupdriver=cgroupfs
# 從新加載配置
systemctl daemon-reload
# 重啓docker
systemctl restart docker

# 關閉selinux
sudo setenforce 0

# 文件權限
sudo chmod -R 777 /etc/kubernetes/addons/

# 啓動kubelet服務,注意:可能須要第一次容許minikube start後纔會拉取kubelet
systemctl enable kubelet.service

啓動minikube

If you are running within a VM, your hypervisor does not allow nested virtualization. You will need to use the None (bare-metal) driver

由於服務自己已經安裝在vm虛擬機上,因此這裏使用--vm-driver=none裸機運行docker

sudo minikube start --vm-driver=none

開啓 minikube dashboard

儀表板是基於Web的Kubernetes用戶界面。您可使用儀表板將容器化的應用程序部署到Kubernetes集羣,對容器化的應用程序進行故障排除以及管理集羣資源。您可使用Dashboard來概述集羣上運行的應用程序,以及建立或修改單個Kubernetes資源(例如Deployments,Jobs,DaemonSets等)。例如,您可使用部署嚮導來擴展部署,啓動滾動更新,從新啓動Pod或部署新應用程序。
儀表板還提供有關集羣中Kubernetes資源狀態以及可能發生的任何錯誤的信息。

clipboard.png

若是是直接安裝在macOS上,可使用minikube dashboardcentos

$ sudo minikube dashboard

🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
http://127.0.0.1:46727/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

#### 宿主機瀏覽器訪問

由於咱們使用的是centos 7 minimal只有終端環境,因此咱們要在宿主機上進行瀏覽器訪問,不須要執行minikube dashboard,使用以下命令開啓proxyapi

sudo kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'

而且使用以下地址訪問便可瀏覽器

http://xxx.xxx.xxx.xxx:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy

IP獲取

要獲取xxx.xxx.xxx.xxx的虛擬機ip,可使用以下命令。app

sudo minikube ip

參考資料

《WEB UI (Dashboard)》tcp

《minikube linux installation》

《安裝並設置 kubectl》

《經過 Minikube 在本地運行 Kubernetes》

報錯+解決方案

問題

sudo minikube start --vm-driver=none
sudo: minikube:找不到命令

解決辦法
/usr/local/bin添加到secure_path後面,保存後當即生效

su root
vi /etc/sudoers
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

問題

Unable to start VM: create: precreate: exec: "docker": executable file not found in $PATH

解決辦法

sudo yum install docker

問題

💣  Error starting cluster: cmd failed: sudo env PATH=/var/lib/minikube/binaries/v1.16.0:$PATH kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap

: running command: sudo env PATH=/var/lib/minikube/binaries/v1.16.0:$PATH kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap
 output: [init] Using Kubernetes version: v1.16.0
[preflight] Running pre-flight checks
    [WARNING Firewalld]: firewalld is active, please ensure ports [8443 10250] are open or your cluster may not function correctly
    [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
    [WARNING Swap]: running with swap on is not supported. Please disable swap
    [WARNING FileExisting-socat]: socat not found in system path
    [WARNING Hostname]: hostname "minikube" could not be reached
    [WARNING Hostname]: hostname "minikube": lookup minikube on 10.211.55.1:53: no such host
    [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
: running command: sudo env PATH=/var/lib/minikube/binaries/v1.16.0:$PATH kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap
.: exit status 1

😿  Sorry that minikube crashed. If this was unexpected, we would love to hear from you:
👉  https://github.com/kubernetes/minikube/issues/new/choose

解決辦法

systemctl stop firewalld
swapoff -a
systemctl enable docker.service
systemctl enable kubelet.service

問題

failed to run Kubelet: failed to create kubelet: misconfiguration: kubelet cgroup driver: "cgroupfs" is different from docker cgroup driver: "systemd"

解決辦法

vi /lib/systemd/system/docker.service

修改成cgroupfs
systemctl daemon-reload
systemctl restart docker

問題

❌  Problems detected in kube-addon-manager [13ce287ce3f6]:
    error: Error loading config file "/var/lib/minikube/kubeconfig": open /var/lib/minikube/kubeconfig: permission denied
    error: Error loading config file "/var/lib/minikube/kubeconfig": open /var/lib/minikube/kubeconfig: permission denied
    error: Error loading config file "/var/lib/minikube/kubeconfig": open /var/lib/minikube/kubeconfig: permission denied

解決辦法

setenforce 0

問題

minikube dashboard
🔌  Enabling dashboard ...

💣  Unable to enable dashboard: [enabling addon deploy/addons/dashboard/dashboard-clusterrole.yaml: error creating file at /etc/kubernetes/addons/dashboard-clusterrole.yaml: open /etc/kubernetes/addons/dashboard-clusterrole.yaml: permission denied]

解決辦法

sudo chmod -R 777 /etc/kubernetes/addons/

問題

kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'
Starting to serve on [::]:8001
2019/09/23 18:22:52 http: proxy error: dial tcp [::1]:8080: connect: connection refused
2019/09/23 18:22:53 http: proxy error: dial tcp [::1]:8080: connect: connection refused
2019/09/23 18:22:53 http: proxy error: dial tcp [::1]:8080: connect: connection refused

解決辦法
kubectl +sudo執行

sudo kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'
相關文章
相關標籤/搜索