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