作者:浪费小创_512 | 来源:互联网 | 2023-10-12 18:18
minikube安装过程介绍minikubeMinikube是一个可以在本地轻松运行Kubernetes的工具。Minikube会在您的笔记本电脑中的虚拟机上运行一个单节点的Kub
minikube 安装过程
介绍
minikube
Minikube 是一个可以在本地轻松运行 Kubernetes 的工具。Minikube 会在您的笔记本电脑中的虚拟机上运行一个单节点的 Kubernetes 集群,以便用户对 Kubernetes 进行试用或者在之上进行 Kubernetes 的日常开发。
kubectl
kubectl是用于针对Kubernetes集群运行命令的命令行接口。
安装
环境
安装环境:parallels 虚拟机
操作系统:centos 7 minimal
过程
环境初始化
初始化所需要执行的命令,都是根据在安装过程中遇到的报错,给出的解决办法整理。
# 安装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
裸机运行
sudo minikube start --vm-driver=none
开启 minikube dashboard
仪表板是基于Web的Kubernetes用户界面。您可以使用仪表板将容器化的应用程序部署到Kubernetes集群,对容器化的应用程序进行故障排除以及管理集群资源。您可以使用Dashboard来概述集群上运行的应用程序,以及创建或修改单个Kubernetes资源(例如Deployments,Jobs,DaemonSets等)。例如,您可以使用部署向导来扩展部署,启动滚动更新,重新启动Pod或部署新应用程序。
仪表板还提供有关集群中Kubernetes资源状态以及可能发生的任何错误的信息。
如果是直接安装在macOS上,可以使用minikube dashboard
$ 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
,使用如下命令开启proxy
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,可以使用如下命令。
sudo minikube ip
参考资料
《WEB UI (Dashboard)》
《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='^*$'