Kubernetes 是一个强大的容器编排平台,而 Minikube 是设置本地 Kubernetes 集群以进行开发和测试的完美工具。AlmaLinux是一个社区驱动的Linux发行版,为这一努力提供了坚实的基础。
在AlmaLinux 9上安装Minikube
第 1 步。在开始安装过程之前,请确保您的 AlmaLinux 9 系统是最新的。在终端中运行以下命令:
<span class="pln">sudo dnf clean all sudo dnf update</span>
第一个命令清理包缓存,第二个命令执行系统更新。
第 2 步。安装必要的软件包。
Minikube依赖于一些软件包。使用以下方法安装它们:dnf
<span class="pln">sudo dnf install </span><span class="pun">-</span><span class="pln">y curl kubectl</span>
第 3 步。设置具有 sudo 权限的非根用户。
最佳实践是为Minikube创建一个专用的非root用户。替换为所需的用户名:meilanamaria
<span class="pln">sudo useradd </span><span class="pun">-</span><span class="pln">m </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash meilanamaria sudo passwd yourusername sudo usermod </span><span class="pun">-</span><span class="pln">aG wheel meilanamaria</span>
现在,切换到您的新用户:
<span class="pln">su </span><span class="pun">-</span><span class="pln"> meilanamaria</span>
第 4 步。在AlmaLinux 9上安装Minikube。
在运行Minikube之前,您需要设置虚拟化环境。首先,检查您的 CPU 是否支持硬件虚拟化:
<span class="pln">grep </span><span class="pun">-</span><span class="pln">E </span><span class="str">'svm|vmx'</span> <span class="pun">/</span><span class="pln">proc</span><span class="pun">/</span><span class="pln">cpuinfo</span>
如果有输出,则 CPU 支持虚拟化。接下来,安装 KVM 相关软件包:
<span class="pln">sudo dnf install </span><span class="pun">-</span><span class="pln">y </span><span class="lit">@virtualization</span>
启用并启动 和 服务:libvirtd
virtlockd
<span class="pln">sudo systemctl enable </span><span class="pun">--</span><span class="pln">now libvirtd virtlockd</span>
Kubectl 是用于与 Kubernetes 集互的命令行工具。让我们安装它:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">LO </span><span class="str">"https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"</span><span class="pln"> chmod </span><span class="pun">+</span><span class="pln">x kubectl sudo mv kubectl </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span>
Minikube 本身是一个在虚拟机内运行的轻量级 Kubernetes 实现。安装方法如下:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">LO https</span><span class="pun">:</span><span class="com">//storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64</span><span class="pln"> sudo install minikube</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">amd64 </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">minikube</span>
第5步。正在配置 Minikube。
现在安装了Minikube,你可以启动它:
<span class="pln">minikube start </span><span class="pun">--</span><span class="pln">driver</span><span class="pun">=</span><span class="pln">kvm2</span>
此命令使用 KVM2 驱动程序初始化 Minikube。这可能需要几分钟,所以请耐心等待。启动并运行后,你将看到一条消息,确认群集已创建。
验证您的 Minikube 集群的状态:
<span class="pln">minikube status</span>
第 6 步。正在配置 kubectl。
要有效地管理您的 Minikube 集群,您需要配置 kubectl:
<span class="pln">kubectl config </span><span class="kwd">use</span><span class="pun">-</span><span class="pln">context minikube</span>
检查集群状态
<span class="pln">kubectl cluster</span><span class="pun">-</span><span class="pln">info</span>
默认情况下,kubectl 与命名空间交互。让我们明确设置它:default
<span class="pln">kubectl config </span><span class="kwd">set</span><span class="pun">-</span><span class="pln">context </span><span class="pun">--</span><span class="pln">current </span><span class="pun">--</span><span class="kwd">namespace</span><span class="pun">=</span><span class="kwd">default</span>
步骤 7.管理米尼库贝。
您现在可以轻松管理您的 Minikube 集群:
<span class="com">### Starting Minikube ###</span><span class="pln"> minikube start </span><span class="com">### Stopping Minikube ###</span><span class="pln"> minikube stop </span><span class="com">### Pausing Minikube ###</span><span class="pln"> minikube pause </span><span class="com">### Resuming Minikube ###</span><span class="pln"> minikube unpause </span><span class="com">### Deleting Minikube ###</span><span class="pln"> minikube </span><span class="kwd">delete</span>
第8步。访问 Kubernetes 仪表板。
Kubernetes 仪表板提供了一个用于管理集群的图形用户界面。让我们设置一下:
<span class="pln">kubectl apply </span><span class="pun">-</span><span class="pln">f https</span><span class="pun">:</span><span class="com">//raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml</span>
从 Web 浏览器访问仪表板:
<span class="pln">kubectl proxy</span>
现在,打开 Web 浏览器并导航到 。http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
第9步。部署您的第一个应用程序。
让我们部署一个简单的 Nginx 应用程序来开始使用。首先,创建一个以以下内容命名的文件:nginx-deployment.yaml
<span class="pln">apiVersion</span><span class="pun">:</span><span class="pln"> apps</span><span class="pun">/</span><span class="pln">v1 kind</span><span class="pun">:</span> <span class="typ">Deployment</span><span class="pln"> metadata</span><span class="pun">:</span><span class="pln"> name</span><span class="pun">:</span><span class="pln"> nginx</span><span class="pun">-</span><span class="pln">deployment spec</span><span class="pun">:</span><span class="pln"> replicas</span><span class="pun">:</span> <span class="lit">2</span><span class="pln"> selector</span><span class="pun">:</span><span class="pln"> matchLabels</span><span class="pun">:</span><span class="pln"> app</span><span class="pun">:</span><span class="pln"> nginx </span><span class="kwd">template</span><span class="pun">:</span><span class="pln"> metadata</span><span class="pun">:</span><span class="pln"> labels</span><span class="pun">:</span><span class="pln"> app</span><span class="pun">:</span><span class="pln"> nginx spec</span><span class="pun">:</span><span class="pln"> containers</span><span class="pun">:</span> <span class="pun">-</span><span class="pln"> name</span><span class="pun">:</span><span class="pln"> nginx</span><span class="pun">-</span><span class="pln">container image</span><span class="pun">:</span><span class="pln"> nginx</span><span class="pun">:</span><span class="pln">latest</span>
将部署应用到群集:
<span class="pln">kubectl apply </span><span class="pun">-</span><span class="pln">f nginx</span><span class="pun">-</span><span class="pln">deployment</span><span class="pun">.</span><span class="pln">yaml</span>
若要验证应用程序是否正在运行,请使用以下命令:
<span class="pln">kubectl </span><span class="kwd">get</span><span class="pln"> pods</span>
感谢您使用本教程在您的 AlmaLinux 9 系统上安装 Minikube。有关其他帮助或有用信息,我们建议您查看Minikube官方网站。