2023-03-15 08:32:44 +08:00
|
|
|
|
[#]: subject: "How to Install MiniKube on RHEL 8/Rocky Linux 8/AlmaLinux 8"
|
|
|
|
|
[#]: via: "https://www.linuxtechi.com/install-minikube-on-rhel-rockylinux-almalinux/"
|
|
|
|
|
[#]: author: "Pradeep Kumar https://www.linuxtechi.com/author/pradeep/"
|
|
|
|
|
[#]: collector: "lkxed"
|
|
|
|
|
[#]: translator: "geekpi"
|
2023-03-15 23:26:54 +08:00
|
|
|
|
[#]: reviewer: "wxy"
|
|
|
|
|
[#]: publisher: "wxy"
|
|
|
|
|
[#]: url: "https://linux.cn/article-15630-1.html"
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
如何在 RHEL 8 上安装 MiniKube
|
2023-03-15 08:32:44 +08:00
|
|
|
|
======
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
![][0]
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
> 在这篇文章中,我们将逐步介绍如何在 RHEL 8、Rocky Linux 8 或 AlmaLinux 8 上安装 MiniKube。
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
MiniKube 是一个跨平台的开源工具,可以让你在本地机器上部署单节点 Kubernetes 集群。
|
|
|
|
|
|
|
|
|
|
Kubernetes,也被称为 k8s,或简称 Kube,是一个开源的容器编排平台,用于容器的自动化扩展和部署。MiniKube 集群帮助开发人员和管理员在集群中构建他们的测试环境。
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
##### MiniKube 的先决条件
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
- 最小化安装的 RHEL 8 或 Rocky Linux 8 或 AlmaLinux 8
|
2023-03-15 08:32:44 +08:00
|
|
|
|
- 本地配置的 RHEL 8 仓库或订阅
|
|
|
|
|
- 至少 2GB RAM 和 2 个 vCPU
|
|
|
|
|
- 20GB 硬盘空间
|
2023-03-15 23:26:54 +08:00
|
|
|
|
- 具有管理员身份的 sudo 用户
|
2023-03-15 08:32:44 +08:00
|
|
|
|
- 稳定的互联网连接
|
|
|
|
|
- Docker 或虚拟机管理器,如 VirtualBox、KVM 和 VMware 等
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
在这篇文章中,我们将使用 Docker 作为 MiniKube 的驱动程序。满足所有先决条件后,现在是时候卷起袖子动手了。
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
### 步骤 1)启用官方 Docker 仓库
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
要启用 Docker 官方仓库,运行:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
|
|
|
|
|
$ sudo dnf repolist
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][1]
|
|
|
|
|
|
|
|
|
|
### 步骤 2)安装 Docker CE(社区版)
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
运行以下 `dnf` 命令来安装 Docker 及其依赖项:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo dnf install docker-ce docker-ce-cli containerd.io -y
|
|
|
|
|
```
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
输出:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
![][2]
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
安装 Docker 后启动并启用它的服务,运行以下 `systemctl` 命令:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo systemctl start docker
|
|
|
|
|
$ sudo systemctl start docker
|
|
|
|
|
```
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
允许你的本地用户在没有 `sudo` 的情况下运行 `docker` 命令,运行:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo usermod -aG docker $USER
|
|
|
|
|
$ newgrp docker
|
|
|
|
|
```
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
### 步骤 3)安装 kubectl 二进制文件
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
`kubectl` 是一个命令行工具,它通过 API 与 Kubernetes 集群进行交互。我们使用 `kubectl` 部署应用。默认情况下,`kubectl` 不包含在 RHEL 8 、Rocky Linux 8 或 AlmaLinux 8 软件包仓库中。因此,我们将使用下面的命令手动安装它:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
|
|
|
|
$ sudo cp kubectl /usr/local/bin/ && sudo chmod +x /usr/local/bin/kubectl
|
|
|
|
|
$ kubectl version --client
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
以上命令的输出如下所示:
|
|
|
|
|
|
|
|
|
|
![][3]
|
|
|
|
|
|
|
|
|
|
### 步骤 4)下载 MiniKube 二进制文件并启动集群
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
安装 `kubectl` 后,让我们使用以下命令下载并安装 MiniKube 二进制文件:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
|
|
|
|
|
$ sudo install minikube-linux-amd64 /usr/local/bin/minikube
|
|
|
|
|
```
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
现在使用下面的命令启动 MiniKube 集群:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ minikube start --driver docker
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][4]
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
上面的输出确认 `minikube` 命令已经使用 `docker` 作为驱动程序启动了单节点 Kubernetes 集群。
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
运行下面的 `minikube` 命令来验证本地 Kubernetes 集群的状态:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
2023-03-15 23:26:54 +08:00
|
|
|
|
$ minikube status
|
2023-03-15 08:32:44 +08:00
|
|
|
|
minikube
|
|
|
|
|
type: Control Plane
|
|
|
|
|
host: Running
|
|
|
|
|
kubelet: Running
|
|
|
|
|
apiserver: Running
|
|
|
|
|
kubeconfig: Configured
|
2023-03-15 23:26:54 +08:00
|
|
|
|
$
|
|
|
|
|
$ minikube ip
|
2023-03-15 08:32:44 +08:00
|
|
|
|
192.168.49.2
|
2023-03-15 23:26:54 +08:00
|
|
|
|
$
|
2023-03-15 08:32:44 +08:00
|
|
|
|
```
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
要停止 MiniKube 集群,请执行:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ minikube stop
|
|
|
|
|
```
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
执行 `kubectl` 命令查看集群和节点信息:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl cluster-info
|
|
|
|
|
$ kubectl get nodes
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][5]
|
|
|
|
|
|
|
|
|
|
### 步骤 5)测试和验证 Kubernetes 集群
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
为了测试 Kubernetes 集群,让我们尝试使用 echo 服务器镜像创建 k8s 部署,它相当于 HTTP Web 服务器并将其作为服务暴露在端口 8080 上:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
2023-03-15 23:26:54 +08:00
|
|
|
|
$ kubectl create deployment test-minikube --image=k8s.gcr.io/echoserver:1.10
|
2023-03-15 08:32:44 +08:00
|
|
|
|
deployment.apps/test-minikube created
|
2023-03-15 23:26:54 +08:00
|
|
|
|
$
|
2023-03-15 08:32:44 +08:00
|
|
|
|
```
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
要访问 `test-minikube` 部署,将其公开为服务,运行以下命令:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
2023-03-15 23:26:54 +08:00
|
|
|
|
$ kubectl expose deployment test-minikube --type=NodePort --port=8080
|
2023-03-15 08:32:44 +08:00
|
|
|
|
service/test-minikube exposed
|
2023-03-15 23:26:54 +08:00
|
|
|
|
$
|
2023-03-15 08:32:44 +08:00
|
|
|
|
```
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
运行以下 `kubectl` 命令以获取上面创建的部署、<ruby>容器荚<rt>pod</rt></ruby> 和服务信息:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl get deployment,pods,svc
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][6]
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
要访问服务,请通过运行下面的命令获取其 URL:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
2023-03-15 23:26:54 +08:00
|
|
|
|
$ minikube service test-minikube --url
|
2023-03-15 08:32:44 +08:00
|
|
|
|
http://192.168.49.2:32291
|
2023-03-15 23:26:54 +08:00
|
|
|
|
$
|
|
|
|
|
$ curl http://192.168.49.2:32291/
|
2023-03-15 08:32:44 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][7]
|
|
|
|
|
|
|
|
|
|
太好了,这意味着我们的 Kubernetes 集群工作正常,因为我们能够访问我们的示例应用。
|
|
|
|
|
|
|
|
|
|
##### 步骤 6)启用 MiniKube 插件
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
MiniKube 提供插件,可以为我们的集群添加额外的功能。要列出所有可用的插件,运行:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ minikube addons list
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][8]
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
Kubernetes 附带一个仪表板,可让你管理集群。在 MiniKube 中,仪表板已作为插件添加。所以要启用它,运行:
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ minikube addons enable dashboard
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
还要启用 nginx 入口控制器,运行:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ minikube addons enable ingress
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][9]
|
|
|
|
|
|
|
|
|
|
要访问仪表板,运行:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ minikube dashbaord --url
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
这将在你系统的浏览器中启动仪表板。
|
|
|
|
|
|
|
|
|
|
![][10]
|
|
|
|
|
|
2023-03-15 23:26:54 +08:00
|
|
|
|
就是这些了。我们已经成功地在 RHEL 8、Rocky Linux 8 或 AlmaLinux 8 上使用 MiniKube 安装了 Kubernetes。欢迎你在下面的评论部分分享你的反馈和意见。
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
via: https://www.linuxtechi.com/install-minikube-on-rhel-rockylinux-almalinux/
|
|
|
|
|
|
|
|
|
|
作者:[Pradeep Kumar][a]
|
|
|
|
|
选题:[lkxed][b]
|
|
|
|
|
译者:[geekpi](https://github.com/geekpi)
|
2023-03-15 23:26:54 +08:00
|
|
|
|
校对:[wxy](https://github.com/wxy)
|
2023-03-15 08:32:44 +08:00
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
|
|
|
|
|
|
|
|
[a]: https://www.linuxtechi.com/author/pradeep/
|
|
|
|
|
[b]: https://github.com/lkxed/
|
2023-03-15 23:26:54 +08:00
|
|
|
|
[1]: https://www.linuxtechi.com/wp-content/uploads/2020/04/Enable-Docker-Repo-RHEL8-Rocky-Linux8-1024x203.png
|
2023-03-15 08:32:44 +08:00
|
|
|
|
[2]: https://www.linuxtechi.com/wp-content/uploads/2020/04/Install-Docker-DNF-Command-RHEL8-RockyLinux8.png
|
|
|
|
|
[3]: https://www.linuxtechi.com/wp-content/uploads/2020/04/Download-Kubectl-Binary-RHEL8-RockyLinux8.png
|
|
|
|
|
[4]: https://www.linuxtechi.com/wp-content/uploads/2020/04/Start-Minikube-Cluster-RHEL8-Rocky-Linux8.png
|
2023-03-15 23:26:54 +08:00
|
|
|
|
[5]: https://www.linuxtechi.com/wp-content/uploads/2020/04/K8s-cluster-info-RHEL8-RockyLinux9-1024x193.png
|
|
|
|
|
[6]: https://www.linuxtechi.com/wp-content/uploads/2020/04/Kubectl-get-pods-deplyments-service-rhel8-rocky-linux8.png
|
|
|
|
|
[7]: https://www.linuxtechi.com/wp-content/uploads/2020/04/Access-Application-minikube-rhel8-rockylinux8.png
|
|
|
|
|
[8]: https://www.linuxtechi.com/wp-content/uploads/2020/04/minikube-addons-list-rhel8-rockylinux8.png
|
|
|
|
|
[9]: https://www.linuxtechi.com/wp-content/uploads/2020/04/Enable-Minikube-addons-RHEL8-RockyLinux9-1024x381.png
|
|
|
|
|
[10]: https://www.linuxtechi.com/wp-content/uploads/2020/04/Kubernetes-Dashboard-MiniKube-Dashboard.png
|
|
|
|
|
[0]: https://img.linux.net.cn/data/attachment/album/202303/15/232024hn8312yg1qmy7mhv.jpg
|