Kubernetes入门-07.Minikube: 安装本地kubernetes集群
本系列课程翻译自Linux Foundation开源软件学园的课程——kubernetes入门(LFS158)
Chapter Overview
Minikube is one of the easiest, most flexible and popular methods to run an all-in-one or a multi-node local Kubernetes cluster, isolated by Virtual Machines (VM) or Containers, run directly on our workstations. Minikube is the tool responsible for the installation of Kubernetes components, cluster bootstrapping, and cluster tear-down when no longer needed. It includes additional features aimed to ease the user interaction with the Kubernetes cluster, but nonetheless, it initializes for us a fully functional, non-production, Kubernetes cluster extremely convenient for learning purposes. Minikube can be installed on native macOS, Windows, and many Linux distributions.
In this chapter, we will explore the requirements to install Minikube locally on our workstation.
译:
Minikube是一个超级易用,超级灵活和流行的,用来运行一个all-in-one或者多节点本地kubernetes集群的方法,与虚拟机或容器进行隔离,直接运行在我们的工作站上。
Minikube是一个工具,用来安装kubernetes的组件、集群引导、节点清理(当不再需要的时候)。它包含了一些额外的特性,旨在简化用户与kubernetes集群的交互,不过尽管如此,它还是提供了我们一个完整功能的、用于学习目的的非生产级别的kubernetes集群。minikube可以安装在原生的macOS、Windows、和许多linux发行版上。
在这个章节中,我们将探索在我们工作站本地安装Minikube的相关要求。
Learning Objectives
By the end of this chapter, you should be able to:
- Install Minikube on the native OS of your workstation.
- Verify the local installation.
译:
在本章的末尾,你应该能够:
- 在我们工作站原生的操作系统上安装Minikube;
- 验证本地安装
What Is Minikube?
Minikube is one of the easiest, most flexible and popular methods to run an all-in-one or a multi-node local Kubernetes cluster directly on our local workstations. It installs and runs on any native OS such as Linux, macOS, or Windows. However, in order to fully take advantage of all the features Minikube has to offer, a Type-2 Hypervisor or a Container Runtime should be installed on the local workstation, to run in conjunction with Minikube. The role of the hypervisor or container runtime is to offer an isolated infrastructure for the Minikube Kubernetes cluster components, that is easily reproducible, easy to use and tear down. This isolation of the cluster components from our daily environment ensures that once no longer needed, the Minikube components can be safely removed leaving behind no configuration changes to our workstation, thus no traces of their existence. This does not mean, however, that we are responsible for the provisioning of any VMs or containers with guest operating systems with the help of the hypervisor or container runtime. Minikube includes the necessary adapters to interact directly with the isolation software of choice to build all its infrastructure as long as the Type-2 Hypervisor or Container Runtime is installed on our workstation.
译:
Minikube是一个超级易用,超级灵活和流行的,用来运行一个all-in-one或者多节点本地kubernetes集群的方法,与虚拟机或容器进行隔离,直接运行在我们的工作站上。它可以安装和运行在许多原生操作系统,例如Linux、macOS、Windows。然而,为了充分利用Minikube提供的所有特性,一个type-2类型的Hypervisor或者容器运行时需要安装在我们的本地工作站上,用来配合Minikube一起工作。
Hypervisor或者容器运行时的角色,是用来给kubernetes集群组件提供一个隔离的基础设施环境,能便于可再生、便于使用和销毁。这种将集群的组件与我们日常环境做了隔离,能确保一旦有一天我们不需要minikube的时候,它的组件可以被安全地移除并且不会在我们的工作站中留下配置的变化,我们的本地环境也不会再有Minikube的存在。然而这并不意味着我们还需要在hypervisor或容器运行时的帮助下,负责提供带有guest操作系统的虚机和容器。
Minikube包含了必要的转换器,只要在我们的工作站上安装了Type-2的Hypervisor或容器运行时,minikube及其适配器就可以与所选择的隔离软件进行交互并构建所有的基础设施。
注:
Type-2类型的hypervisor是什么意思?
答:运行在宿主操作系统上的一种虚拟化技术,它依赖于宿主操作系统来进行资源分配与隔离。例如Vmware Workstation,virtualBox等。
Type-1类型的hypervisor是什么意思呢?
答:直接在裸金属上的虚拟化技术,由于不依赖宿主操作系统,而是直接操控硬件进行资源分配与隔离,它的性能相比type-2更好,但也更难部署。常见的有VMWare ESXi,Windows Hyper-V,Xen等
Minikube is built on the capabilities of the libmachine library originally designed by Docker to build Virtual Machine container hosts on any physical infrastructure. In time Minikube became very flexible, supporting several hypervisors and container runtimes, depending on the host workstation's native OS.
译:
Minikube是基于Libmachine库的能力来构建的,后者是由Docker设计用于在任何的物理基础设施上构建虚拟机容器主机。因此Minikube可以非常灵活,支持多种Hypervisor和容器运行时,取决于我们的主机工作站上的原生操作系统。
For those who feel more adventurous, Minikube can be installed without an isolation software, on bare-metal, which may result in permanent configuration changes to the host OS. To prevent such permanent configuration changes, a second form of isolation can be achieved by installing Minikube inside a Virtual Machine provisioned with a Type-2 Hypervisor of choice, and a desktop guest OS of choice (with enabled GUI). As a result, when installed inside a VM, Minikube will end up making configuration changes to the guest environment, still isolated from the host workstation. Therefore, now we have two distinct methods to isolate the Minikube environment from our host workstation.
译:
对于具有冒险精神的用户而言,Minikube可以不需要隔离软件来进行安装,在裸金属上,这可能会造成主机操作系统上永久的配置变化。为了防止这样的永久性配置变化,隔离的第二种方式就是把minikube安装在一个由二类hypervisor所提供的虚拟机内,以及一个桌面的guest操作系统(开启GUI)。最终结果是,当我们在VM中安装Minikube时,minikube的配置变更事实上是在Guest环境中的,依然与我们主机工作站做了隔离。到目前为止,我们拥有了两种不同方案来把minikube环境和我们的主机工作站进行隔离。
The isolation software can be specified by the user with the --driver option, otherwise Minikube will try to find a preferred method for the host OS of the workstation.
译:
隔离软件可以由用户来指定,通过--drvier选项就可以了,否则minikube会尝试选择一个适用于工作站操作系统的优选方案。
Once decided on the isolation method, the next step is to determine the required number of Kubernetes cluster nodes, and their sizes in terms of CPU, memory, and disk space. Minikube invokes the hypervisor of choice to provision the infrastructure VM(s) which will host the Kubernetes cluster node(s), or the runtime of choice to run infrastructure container(s) that host the cluster node(s). Keep in mind that Minikube now supports all-in-one single-node and multi-node clusters. Regardless of the isolation method and the expected cluster and node sizes, a local Minikube Kubernetes cluster will ultimately be impacted and/or limited by the physical resources of the host workstation. We have to be mindful of the needs of the host OS and any utilities it may be running, then the needs of the hypervisor or the container runtime, and finally the remaining resources that can be allocated to our Kubernetes cluster. For a learning environment the recommendations are that a Kubernetes node has 2 CPU cores (or virtual CPUs) at a minimum, at least 2 GB of RAM memory (with 4 - 8 GB of RAM recommended for optimal usage), and 20+ GB of disk storage space. When migrating towards a larger, more dynamic, production grade cluster, these resource values should be adjusted accordingly. The Kubernetes nodes are expected to access the internet as well, for software updates, container image downloads, and for client accessibility.
译:
当我们决定了用哪种方法来做隔离,下一步就是决定kubernetes集群节点的数量,以及它们的规格,比如CPU、内存、磁盘容量等。Minikube会调用我们所选择的Hypervisor来提供基础设施虚拟机,用以承载kubernetes集群的工作节点,或者是调用我们选择的容器运行时来运行一个基础架构容器,用以承载集群节点。需要记住的是,Minikube支持创建all-in-one的单节点和多节点集群。无论我们所选择的隔离方式如何,无论我们期望的集群节点规格如何,一个本地的minikube kubernetes集群最终都会受到本地工作站的物理资源的影响和限制。我们必须要留意工作站的操作系统及必要工具运行所消耗的资源,然后是Hypervisor和容器运行时的资源需求,最终剩下的资源才会被用来分配给我们的kubernetes集群。对于一个学习环境来说,我们推荐配置是:节点至少需要2个CPU核数(或者虚拟CPU),至少2GB内存(4-8GB内存会更优),以及20+GB的磁盘存储空间。当我们迁移到一个更大的、更动态的生产级别集群时,这些资源需要根据实际需求来进行调整。另外kubernetes节点也需要访问internet,用来做软件升级、容器镜像下载和客户端访问。
Following the node(s)' provisioning phase, Minikube invokes kubeadm, to bootstrap the Kubernetes cluster components inside the previously provisioned node(s). We need to ensure that we have the necessary hardware and software required by Minikube to build our environment.
接下来是node提供的阶段,Minikube将调用kubeadm,来在之前提供的节点中引导kubernetes集群组件。我们需要确保我们拥有足够多的硬件资源和minikube构建环境所需的软件需求。
Requirements for Running Minikube
Here we outline the requirements to run Minikube on our local workstation.
Requirements
- VT-x/AMD-v virtualization
VT-x/AMD-v virtualization may need to be enabled on the local workstation for certain hypervisors. - kubectl
kubectl command line client (CLI) is a binary used to access and manage any Kubernetes cluster. It is installed through Minikube and accessed through the minikube kubectl command, or it can be installed separately and run as a standalone tool. We will explore kubectl installation and usage in future chapters. - Type-2 hypervisor or container runtime
Without a specified driver, Minikube will try to find an installed hypervisor or a runtime, in the following order of preference (on a Linux host): docker, kvm2, podman, vmware, and virtualbox. If multiple isolation software installations are found, such as docker and virtualbox, Minikube will pick docker over virtualbox if no desired driver is specified by the user. Hypervisors and Container Runtimes supported by various native workstation OSes:- On Linux VirtualBox, KVM2, and QEMU hypervisors, or Docker and Podman runtimes.
- On macOS VirtualBox, HyperKit, VMware Fusion, Parallels, and QEMU hypervisors, or Docker and Podman runtimes.
- On Windows VirtualBox, Hyper-V, VMware Workstation, and QEMU hypervisors, or Docker and Podman runtimes.
NOTE: Minikube supports a --driver=none (on Linux) option that runs the Kubernetes components bare-metal, directly on the host OS and not inside a VM. With this option a Docker installation is required and a Linux OS on the local workstation, but no hypervisor installation. This driver is recommended for advanced users.
- Internet connection on the first Minikube run
This is needed to download packages, dependencies, updates and pull images needed to initialize the Minikube Kubernetes cluster components. Subsequent Minikube runs will require an Internet connection only when new container images need to be pulled from a public container registry or when deployed containerized applications need it for client accessibility. Once a container image has been pulled, it can be reused from the local container runtime image cache without an Internet connection.
译:
下面是我们罗列出的,在我们本地工作站上运行Minikube的需求:
- VT-x/AMD-v虚拟化
对于一些特定的hypervisor来说,VT-x/AMD-v虚拟化可能需要在本地工作站中开启
- Kubectl
kubectl命令行客户端是一个二进制文件,用来访问和管理任意的kubernetes集群。在安装Minikube的时候会安装该工具,并且需要通过minikube kubectl命令来进行访问,它也可以和minikube分开安装,作为独立的工具来使用,我们将在未来章节中探索kubectl的安装和使用。。
- 二类hypervisor或容器运行时
如果没有指定driver,Minikube会尝试寻找一个已安装的Hypervisor或者容器运行时,它会按如下顺序来匹配(在一个LInux主机):docker,kvm2,podman,vmware,virtualbox。如果找到了已安装了多个隔离软件,例如docker和virtualbox,Minikube将会选择优先选择docker(如果用户没有指定期望的driver的话)。Hypervisor和容器运行时由多种原生的工作站操作系统所支持:
- 在Linux上:支持VirtualBox、KVM2、QEMU hypervisor,或者Docker、Podman容器运行时;
- 在macOS上:支持VirtualBox、HyperKit、VMWare Fusion、Parallels、QEMU hypervisor,以及Docker和Podman运行时
- 在Windows上,支持VirtualBox、Hyper-V、VMWare Workstation、QEMUE hypervisor,以及Docker和Podman运行时
需要注意:minikube支持--driver=none(在Linux)选项,来在裸金属上运行kubernetes组件,直接安装在宿主机OS上而不是一个VM中。这种选项,需要已安装Docker,以及本地工作站上运行Linux操作系统,并且没有安装Hypervisor。这种驱动方式推荐进阶用户使用。
In this ch ents of the Kubernetes cluster. While no longer the preferred driver due to slower startup times when compared with other methods, it is still one of the most stable drivers for Minikube on Linux and Windows. However, the VirtualBox hypervisor is no longer compatible with macOS on ARM chipset (M1, M2, and M3), therefore Docker will be used instead.
Read more about Minikube from the official Minikube documentation, the official Kubernetes documentation, or GitHub.
译:
在这个章节中,我们使用一个最健壮、最稳定的隔离方式为驱动,即“VirtualBox”hypervisor,由它提供虚拟机托管kubernetes集群的组件。虽然它相对其他方式存在启动时间较慢的短板,因而不再是大家首选的驱动器,但它仍然是在Linux和Windows上运行Minikube最稳定的驱动之一。然而,VirtualBox Hypervisor还没有与arm芯片的macOS适配(M1,M2,M3),因此由Docker来代替。
你可以从官方Minikube文档,官方Kubernetes文档或者Github来了解更多关于Minikube的资料。
Installing Minikube on Linux
Let's learn how to install the latest Minikube release on Ubuntu Linux 22.04 LTS with VirtualBox v7.0 specifically. This installation assumes no other isolation software is installed on our Linux workstation, such as KVM2, QEMU, Docker Engine or Podman, that Minikube can use as a driver.
NOTE: For other Linux OS distributions or releases, VirtualBox and Minikube versions, the installation steps may vary! Check the Minikube installation for specific installation instructions!
译:
让我们来学习如何安装最新的Minikube版本,操作系统我们使用Ubuntu Linux 22.04LTS,VirtualBox使用v7.0版本。这个安装假设在我们的Linux工作站上没有安装其他隔离软件,比如KVM2,QEMU,Docker Engine或Podman,这些Minikube可以用作driver的隔离软件。
Verify the virtualization support on your Linux OS in a terminal (a non-empty output indicates supported virtualization):
$ grep -E --color 'vmx|svm' /proc/cpuinfo
The easiest way to download and install the VirtualBox hypervisor for Linux is from its official download site. VirtualBox is available for many Linux distributions such as Oracle Linux, RHEL, CentOS 7, Ubuntu, Debian, openSUSE, and Fedora.
译:
我们可以通过终端来验证我们的Linux操作系统是否支持虚拟化。(非空输出便表示支持虚拟化)
$ grep -E --color 'vmx|svm' /proc/cpuinfo
最简单的下载和安装VirtualBox Hypervisor(Linux)的方式是从其官方下载站。VirtualBox在大部分Linux发行版上都是可用的,比如Oracle Linux、RHEL、CentOS 7、Ubuntu、Debian、openSUSE、Fedora。
Minikube can be easily downloaded and installed in a terminal. Either the latest release or a specific release available from the Minikube release page can be installed by running the following commands. While these installation commands reflect the official installation guide at the time of this course content update, they may change in the near future as part of the continuous growth of Kubernetes. It is strongly recommended to inspect the official installation guide for Linux > x86-64 > Stable when attempting the installation, to ensure the most up-to-date package repositories are used in the process. Below we are presenting the Binary download option, a distribution neutral installation approach:
$ curl -LO \
https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64
$ sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
NOTE: Replacing /latest/ with a particular version, such as /v1.31.2/ will download that specified Minikube version.
译:
Minikube可以在终端中轻松地下载和安装。无论是最新版,还是从Minikube Release Page上找到的指定版本,我们都可以运行如下地命令来进行安装。我们列出的安装命令是在本课程内容发布时官网提供的指导,随着kubernetes的持续发展,安装命令可能会在不久后发生变化。因此我们强烈建议大家在安装时参考Minikube的官方指导(Linux > x86-64 > Stable),这样能保证在执行过程中使用最新的安装包仓库。下面我们展示的是二进制下载选项,这是一个发行版中立(即适用于大多数发行版)的安装方法。
$ curl -LO \
https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64
$ sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
注意:替换/latest字段为特定的版本号,比如/v1.13.2,将会下载指定版本的Minikube
Start Minikube. In a terminal we can start Minikube with the minikube start command, which bootstraps a single-node cluster with the latest supported stable Kubernetes version release. For a specific Kubernetes version the --kubernetes-version option can be used as such minikube start --kubernetes-version=v1.27.1 (where latest is default and acceptable version value, and stable is also acceptable). In case there are other virtualization driver candidates for Minikube on the workstation, it is good practice to supply the desired driver with the --driver=virtualbox option. More advanced start options will be explored later in this chapter:
译:
启动Minikube,在终端中我们可以使用minikube start命令来启动Minikube,这将引导一个单节点集群,并且是最新的kubernetes稳定版。如果要指定kubernetes版本,可以使用--kubernetes-version选项,即使用
Minikube start --kubernetes-version=v1.27.1
这样的命令。(latest是默认、可接受的版本值,stable也是可接受的值)如果在我们的工作站上由其他可用的虚拟化driver候选者,最佳实践是显式地指定我们期望的driver,使用--driver=virtualbox选项。更高级的启动参数我们会在本章的最后进行探索。
$ minikube start --driver=virtualbox
😄 minikube v1.32.0 on Ubuntu 22.04
✨ Using the virtualbox driver based on user configuration
💿 Downloading VM boot image ...
> minikube-v1.32.1-amd64.iso....: 65 B / 65 B [---------] 100.00% ? p/s 0s
> minikube-v1.32.1-amd64.iso: 292.96 MiB / 292.96 MiB 100.00% 31.34 MiB p
👍 Starting control plane node minikube in cluster minikube
💾 Downloading Kubernetes v1.28.3 preload ...
> preloaded-images-k8s-v18-v1...: 403.35 MiB / 403.35 MiB 100.00% 32.19 M
🔥 Creating virtualbox VM (CPUs=2, Memory=6000MB, Disk=20000MB) ...
🐳 Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
💡 kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
NOTE: An error message that reads "Unable to pick a default driver..." means that Minikube was not able to locate any one of the supported hypervisors or runtimes. The recommendation is to install or re-install a desired isolation tool, and ensure its executable is found in the default PATH of your OS distribution.
NOTE: An error message that reads “The vboxdrv kernel module is not loaded” means that a critical VirtualBox kernel module may not be available. First, try to re-install VirtualBox on the workstation. Second, try installing a C compiler that may be missing from your workstation and then build the kernel module. For the Ubuntu 22.04 LTS OS the required gcc compiler can be downloaded and installed from Ubuntu – Package Download Selection -- gcc-12_12.3.0-1ubuntu1~22.04_amd64.deb. The kernel module can be built with the sudo /sbin/vboxconfig command. After a successful rebuild, attempt to start minikube again with virtualbox using the command above.
Check the status. With the minikube status command, we display the status of the Minikube cluster:
译:
注意:一个错误信息“Unable to pick a default driver”意味着Minikube没有定位到任何它可以使用的Hypervisor或容器运行时。建议就是安装或者重新安装一个期望的隔离工具,并且确保它在您操作系统上的默认“PATH”是可以执行的。
注意:一个错误信息“The vboxdrv kernel module is not loaded”意味着一个关键的VirtualBox内核模块不可用。首先,尝试在工作站上重新安装VirtualBox;其次,尝试安装一个C编译器,这可能是工作站上缺失的一个资料,然后再构建kernel模块。对于Ubuntu 22.04LTS版操作系统,需要的gcc编译器可以在上述链接中下载和安装。Kernel模块可以通过sudo /sbin/vboxconfig命令进行构建。在成功重新编译后,尝试再次用刚才的命令启动minikube。
检查状态,使用minikube status命令,我们显示了minikube集群的状态
$ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
Stop Minikube. With the minikube stop command, we can stop Minikube. This command stops all applications running in Minikube, safely stops the cluster and the VirtualBox VM, preserving our work until we decide to start the Minikube cluster once again, while preserving the Minikube VM:
$ minikube stop
✋ Stopping node "minikube" ...
🛑 1 node stopped.
译:
停止minikube。
使用minikube stop命令,我们可以停止minikube。这个命令将会停止minikube中运行的所有应用程序。安全地停止集群和VirtualBox虚拟机,保存我们的工作直到我们决定再次启动minikube集群,同时保留minikube虚机
When it is time to run the cluster again, simply run the minikube start command (driver option is not required), and it will restart the earlier bootstrapped Minikube cluster.
Remove Minikube. The minikube delete command completely removes Minikube and the Minikube VM. This command should be attempted only when the Minikube cluster is to be decommissioned. All work will be lost after the completion of this command:
$ minikube delete
🔥 Deleting "minikube" in virtualbox ...
💀 Removed all traces of the "minikube" cluster.
译:
当需要再次运行集群的时候,我们只需要简单执行minikube start命令(这时不需要driver选项了),它就会重启早前我们已经引导启动过的minikube集群。
移除Minikube。
Minikube delete命令将会完全移除minikube和minikube虚机。这个命令只应当在minikube集群确定将要下线的时候使用。在这个命令执行完成后,所有的工作都将丢失。
Installing Minikube on macOS(未翻译)
Let's learn how to install the latest Minikube release on macOS with VirtualBox v7.0 or Docker Desktop. This installation assumes no other isolation software is installed on our Mac workstation, such as HyperKit, VMware Fusion, Parallels, or QEMU, that Minikube can use as a driver.
Users of macOS on Intel processors can still use the VirtualBox hypervisor. However, due to lack of ARM architecture support from the latest VirtualBox hypervisor releases, macOS users with M1, M2, and M3 workstations are encouraged to use Docker Desktop instead. While we only need the Docker Engine, the official installation instructions are for the entire Docker Desktop suite.
NOTE: For other hypervisors or container runtimes and Minikube versions the installation steps may vary! Check the Minikube installation for specific installation instructions!
Install Docker Desktop for Mac from its official download site. Keep in mind that there are distinct installation instructions for the two supported processor architectures - the earlier Intel and the latest ARM (M1, M2, M3) respectively. Carefully select the Docker Desktop installation options for your Mac architecture.
Install Minikube. We can download and install in a terminal the latest release or a specific release from the Minikube release page by running the following commands. While these installation commands reflect the official installation guide at the time of this course content update, they may change in the near future as part of the continuous growth of Kubernetes. It is strongly recommended to inspect the official installation guide for macOS > x86-64 > Stable and macOS > ARM64 > Stable respectively when attempting the installation, to ensure the most up-to-date package repositories are used in the process for the target Mac architecture. In addition, inspect the Known Issues section on the Minikube Docker driver page for usage tips and recommendations in case of unexpected behaviors of the Docker installation. Below we are presenting the Binary download option, a distribution neutral installation approach. For the Intel (x86-64) architecture run the following commands:
$ curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-darwin-amd64
$ sudo install minikube-darwin-amd64 /usr/local/bin/minikube
For the ARM64 architecture run the following commands:
$ curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-darwin-arm64
$ sudo install minikube-darwin-arm64 /usr/local/bin/minikube
NOTE: Replacing /latest/ with a particular version, such as /v1.31.2/ will download that specified version.
Start Minikube. We can start Minikube with the minikube start command, which bootstraps a single-node cluster with the latest supported stable Kubernetes version release. For a specific Kubernetes version the --kubernetes-version option can be used as such minikube start --kubernetes-version=v1.27.1 (where latest is default and acceptable version value, and stable is also acceptable). In case there are other virtualization driver candidates for Minikube on the workstation, it is good practice to supply the desired driver with the --driver=docker option. More advanced start options will be explored later in this chapter:
$ minikube start --driver=docker
😄 minikube v1.32.0 on Darwin 12.3
✨ Using the docker driver based on user configuration
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
> gcr.io/k8s-minikube/kicbase...: 1.62 KiB / 453.90 MiB [>_] 0.00% ? p/s ?
💾 Downloading Kubernetes v1.28.3 preload ...
> gcr.io/k8s-minikube/kicbase...: 453.90 MiB / 453.90 MiB 100.00% 7.55 Mi
> preloaded-images-k8s-v18-v1...: 372.28 MiB / 372.28 MiB 100.00% 5.82 Mi
🔥 Creating docker container (CPUs=2, Memory=8000MB) ...
🐳 Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
💡 kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
NOTE: An error message that reads "Unable to pick a default driver..." means that Minikube was not able to locate any one of the supported hypervisors or runtimes. The recommendation is to re-install a desired isolation tool, and ensure its executable is found in the default PATH of your OS.
Check the status. With the minikube status command, we display the status of the Minikube cluster:
$ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
Stop Minikube. With the minikube stop command, we can stop Minikube. This command stops all applications running in Minikube, safely stops the cluster and the Docker container, preserving our work until we decide to start the Minikube cluster once again, while preserving the Minikube Docker container:
$ minikube stop
✋ Stopping node "minikube" ...
🛑 1 nodes stopped.
When it is time to run the cluster again, simply run the minikube start command (driver option is not required), and it will restart the earlier bootstrapped Minikube cluster.
Remove Minikube. The minikube delete command completely removes Minikube and the Minikube Docker container. This command should be attempted only when the Minikube cluster is to be decommissioned. All work will be lost after the completion of this command:
$ minikube delete
🔥 Deleting "minikube" in docker ...
💀 Removed all traces of the "minikube" cluster.
Installing Minikube on Windows
Let's learn how to install the latest Minikube release on Windows 10 and 11 with VirtualBox v7.0 specifically. This installation assumes no other isolation software is installed on our Windows workstation, such as Hyper-V, VMware Workstation, QEMU or Docker Engine, that Minikube can use as a driver.
NOTE: For other OS, VirtualBox, and Minikube versions, the installation steps may vary! Check the Minikube installation for specific installation instructions!
Verify the virtualization support on your Windows system (multiple output lines ending with 'Yes' indicate supported virtualization):
PS C:\WINDOWS\system32> systeminfo
Install the VirtualBox hypervisor for 'Windows hosts'. Download and install the .exe package.
NOTE: You may need to disable Hyper-V on your Windows host (if previously installed and used) while running VirtualBox.
Install Minikube. We can download the latest release or a specific release available from the Minikube release page. Once downloaded, we need to make sure it is added to our PATH. There are multiple packages available to download for Windows, found under a Minikube release. However, downloading and installing the minikube-installer.exe will automatically add the executable to the PATH. Let's download and install the latest minikube-installer.exe package.
Start Minikube. We can start Minikube using the minikube start command, which bootstraps a single-node cluster with the latest supported stable Kubernetes version release. For a specific Kubernetes version the --kubernetes-version option can be used as such minikube start --kubernetes-version=v1.27.1 (where latest is default and acceptable version value, and stable is also acceptable). In case there are other virtualization driver candidates for Minikube on the workstation, it is good practice to supply the desired driver with the --driver=virtualbox option. More advanced start options will be explored later in this chapter. Open the PowerShell using the Run as Administrator option and execute the following command:
PS C:\WINDOWS\system32> minikube start --driver=virtualbox
😄 minikube v1.32.0 on Windows 10
✨ Using the virtualbox driver based on user configuration
💿 Downloading VM boot image ...
> minikube-v1.32.1-amd64.iso....: 65 B / 65 B [---------] 100.00% ? p/s 0s
> minikube-v1.32.1-amd64.iso: 292.96 MiB / 292.96 MiB 100.00% 31.34 MiB p
👍 Starting control plane node minikube in cluster minikube
💾 Downloading Kubernetes v1.28.3 preload ...
> preloaded-images-k8s-v18-v1...: 403.35 MiB / 403.35 MiB 100.00% 32.19 M
🔥 Creating virtualbox VM (CPUs=2, Memory=6000MB, Disk=20000MB) ...
🐳 Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
💡 kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
NOTE: An error message that reads "Unable to pick a default driver..." means that Minikube was not able to locate any one of the supported hypervisors or runtimes. The recommendation is to install or re-install a desired isolation tool, and ensure its executable is found in the default PATH of your OS.
Check the status. With the minikube status command, we display the status of the Minikube cluster. Open the PowerShell using the Run as Administrator option and execute the following command:
PS C:\WINDOWS\system32> minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
Stop Minikube. We can stop Minikube using the minikube stop command. This command stops all applications running in Minikube, safely stops the cluster and the VirtualBox VM, preserving our work until we decide to start the Minikube cluster once again, while preserving the Minikube VM. Open the PowerShell using the Run as Administrator option and execute the following command:
PS C:\WINDOWS\system32> minikube stop
✋ Stopping node "minikube" ...
🛑 1 nodes stopped.
When it is time to run the cluster again, simply run the minikube start command (driver option is not required), and it will restart the earlier bootstrapped Minikube cluster.
Remove Minikube. The minikube delete command completely removes Minikube and the Minikube VM. This command should be attempted only when the Minikube cluster is to be decommissioned. All work will be lost after the completion of this command. Open the PowerShell using the Run as Administrator option and execute the following command:
PS C:\WINDOWS\system32> minikube delete
🔥 Deleting "minikube" in virtualbox ...
💀 Removed all traces of the "minikube" cluster.
Advanced Minikube Features (1)
Now that we have familiarized ourselves with the default minikube start command, let's dive deeper into Minikube to understand some of its more advanced features.
译:现在我们已经比较熟悉minikube start命令,现在让我们深入了解Minikube的一些高级特性。
The minikube start by default selects a driver isolation software, such as a hypervisor or a container runtime, if one (VitualBox) or multiple are installed on the host workstation. In addition it downloads the latest Kubernetes version components. With the selected driver software it provisions a single VM named minikube (with hardware profile of CPUs=2, Memory=6GB, Disk=20GB) or container (Docker) to host the default single-node all-in-one Kubernetes cluster. Once the node is provisioned, it bootstraps the Kubernetes control plane (with the default kubeadm tool), and it installs the latest version of the default container runtime, Docker, that will serve as a running environment for the containerized applications we will deploy to the Kubernetes cluster. The minikube start command generates a default minikube cluster with the specifications described above and it will store these specs so that we can restart the default cluster whenever desired. The object that stores the specifications of our cluster is called a profile.
译:
如果主机工作站上安装了一个(VitualBox)或多个,minikube启动默认选择一个驱动程序隔离软件,例如hypervisor或容器运行时。接下来它会下载最新kubernetes版本的组件。使用选定的驱动软件,它会提供一个单独的虚机名叫minikube(硬件规格是CPU=2,Memory=6GB,Disk=20GB),或者容器(Docker)来托管这个默认的单节点all-in-one的kubernetes集群。当这个节点提供出来以后,它会引导启动kubernetes控制平面(通过默认的kubeadm工具),它会安装最新版本的默认容器运行时——docker,这将作为我们部署在k8s集群种的容器化应用的运行环境。minikube start命令使用上面描述的规格创造了一个默认的minikube集群,它将把这些规格说明存储下来,以便我们在有需要的时候重启这个默认的集群。这个存储了我们集群规格的对象叫做profile。
As Minikube matures, so do its features and capabilities. With the introduction of profiles, Minikube allows users to create custom reusable clusters that can all be managed from a single command line client.
The minikube profile command allows us to view the status of all our clusters in a table formatted output. Assuming we have created only the default minikube cluster, we could list the properties that define the default profile with:
译:
随着Minikube的成熟,其特性和能力也在不断完善。由于profile的推出,Minikube允许用户创建自定义的、可重复使用的集群,都可以由一个单独的命令行客户端来进行管理。
Minikube profile命令允许我们以表格形式的输出查看我们集群的状态。这里假设我们创建了一个默认的minikube集群,我们可以罗列出定义默认配置文件的属性。
$ minikube profile list
|----------|------------|---------|----------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|------------|---------|----------------|------|---------|---------|-------|--------|
| minikube | virtualbox | docker | 192.168.59.100 | 8443 | v1.28.3 | Running | 1 | * |
|----------|------------|---------|----------------|------|---------|---------|-------|--------|
This table presents the columns associated with the default properties such as the profile name: minikube, the isolation driver: VirtualBox, the container runtime: Docker, the Kubernetes version: v1.28.3, the status of the cluster - running or stopped. The table also displays the number of nodes: 1 by default, the private IP address of the minikube cluster's control plane VirtualBox VM, and the secure port that exposes the API Server to cluster control plane components, agents and clients: 8443.
What if we desire to create several reusable clusters instead, with other drivers (Docker or Podman - still experimental on Linux) for node isolation, or different Kubernetes versions (v1.27.10 or v1.28.1), another runtime (cri-o or containerd), and possibly 2, 3, or more nodes (if permitted by the resources of our host system)? What if we desire to further customize the cluster with a specific networking option or plugin? The minikube start command allows us to create such custom profiles with the --profile or -p flags. Several of the isolation drivers support creation of node VMs or node containers of custom sizes as well, features that we will not explore in this course as not all are very stable at the time of this writing.
译:
这个表格列出的列于默认属性有关,例如:配置文件名-minikube,隔离driver:virtualBox,容器运行时:Docker,Kubernetes版本:v1.28.3,集群状态:running还是stopped。这个表格还显示了node节点的数量:1为默认,minikube集群控制平面-virtualBox虚机的私有IP地址,以及用来向集群控制平面组件,agent和客户端暴露API Server的安全端口8443.
如果我们期望创建多个可重复使用的集群,使用其他driver(Docker或Podman---在Linux上还是实验功能)来进行节点隔离,或者不同的kubernetes版本,不同的容器运行时,或者是2个、3个或更多节点(假设我们主机操作系统的资源允许的话)?如果我们期望进一步自定义集群,使用指定的网络通信选项或插件呢?Minikube start命令允许我们创建这些自定义的配置文件,只需要使用--profile或者-p参数即可。有些隔离driver支持创建自定义大小的node虚机的或节点容器,这些特性我们并不会在课程中进行探索,因为在编写课程的时间点,有些特性并不十分稳定。
Below are a few examples of more complex start commands that allow custom clusters to be created with Minikube. They assume that the desired driver software (Docker and/or Podman) has been installed on the host workstation. There is no need to download the desired CNI (network plugin) or the container runtime, they will be set up and enabled by Minikube on our behalf:
译:
下面是一些例子,显示了更复杂的start命令,允许通过Minikube来创建自定义集群。它假设了期望的隔离软件(Docker或者Podman)在主机工作站上安装完成。我们没有必要去下载期望的CNI(网络插件)或者容器运行时,它们将由Minikube代表我们设置和启用:
$ minikube start --kubernetes-version=v1.27.10 \
--driver=podman --profile minipod
$ minikube start --nodes=2 --kubernetes-version=v1.28.1 \
--driver=docker --profile doubledocker
$ minikube start --driver=virtualbox --nodes=3 --disk-size=10g \
--cpus=2 --memory=6g --kubernetes-version=v1.27.12 --cni=calico \
--container-runtime=cri-o -p multivbox
$ minikube start --driver=docker --cpus=6 --memory=8g \
--kubernetes-version="1.27.12" -p largedock
$ minikube start --driver=virtualbox -n 3 --container-runtime=containerd \
--cni=calico -p minibox
Once multiple cluster profiles are available (the default minikube and custom minibox), the profiles table will look like this:
译:
当多个集群的配置文件都是可用时(默认的minikube和自定义的minibox),那么profile表格看上去就像下面这样。
$ minikube profile list
|----------|------------|---------|----------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|------------|---------|----------------|------|---------|---------|-------|--------|
| minibox | virtualbox | crio | 192.168.59.101 | 8443 | v1.25.3 | Running | 3 | |
| minikube | virtualbox | docker | 192.168.59.100 | 8443 | v1.25.3 | Running | 1 | * |
|----------|------------|---------|----------------|------|---------|---------|-------|--------|
The active marker indicates the target cluster profile of the minikube command line tool, also known as its context. The target cluster can be set to minibox with the following command:
“Active”标识这个目标集群配置文件,也被周知为上下文。这个目标集群可以通过下面的命令来设置给minikube
$ minikube profile minibox
The target cluster can be set to the default minikube with one of the following commands:
目标集群可以使用默认的minikube以及下面的命令来进行指定
$ minikube profile minikube
$ minikube profile default
Cont’d on the next page.
Advanced Minikube Features (2)
Most minikube commands, such as start, stop, node, etc. are profile aware, meaning that the user is required to explicitly specify the target cluster of the command, through its profile name. The default minikube cluster, however, can be managed implicitly without specifying its profile name. Stopping and re-starting the two clusters listed above, the minibox cluster (explicitly) and the default minikube cluster (implicitly):
译:
大部分minikube命令,例如启动、停止、node等等都是配置文件敏感的,这意味着我们需要显式地支持命令的目标集群。默认的minikube集群,可以不用显式描述,不用列举配置文件名称和规格。如下图所示,关闭和重启两个集群,这个minibox集群(显式地)以及默认minikube集群(隐式的)。
$ minikube stop -p minibox
$ minikube start -p minibox
$ minikube stop
$ minikube start
Additional helpful minikube commands:
To display the version of the current Minikube installation:
译:更多的一些有用的Minikube命令
用于显示当前minikube安装好的版本。
$ minikube version
minikube version: v1.32.0
commit: 8220a6eb95f0a4d75f7f2d7b14cef975f050512d
Completion is a helpful post installation configuration to enable the minikube command to respond to typical auto-completion mechanisms, such as completing a command in the terminal by pressing the TAB key. To enable completion for the bash shell on Ubuntu:
译:自动补全是一个很有用的安装后配置,它使minikube命令能够响应典型的自动完成机制,例如在终端中按TAB键完成命令。要在Ubuntu中启用bash shell的completion功能:
$ sudo apt install bash-completion
$ source /etc/bash_completion
$ source <(minikube completion bash)
If needed, also run the following command:
译:
如果需要,还可以运行如下命令
$ minikube completion bash
A command that allows users to list the nodes of a cluster, add new control plane or worker nodes, delete existing cluster nodes, start or stop individual nodes of a cluster:
译:该命令用于列出集群的节点,添加新的控制平面或工作节点,删除现有的集群节点,启动或停止集群中的单个节点。
$ minikube node list
minikube 192.168.59.100
$ minikube node list -p minibox
minibox 192.168.59.101
minibox-m02 192.168.59.102
minibox-m03 192.168.59.103
To display the cluster control plane node's IP address, or another node's IP with the --node or -n flags:
译:
为了显示cluster控制平面node的IP,以及其他节点的IP——需要--node和-n标识
$ minikube ip
192.168.59.100
$ minikube -p minibox ip
192.168.59.101
$ minikube -p minibox ip -n minibox-m02
192.168.59.102
When a cluster configuration is no longer of use, the cluster's profile can be deleted. It is also a profile aware command - it deletes the default minikube cluster if no profile is specified, or a custom cluster if its profile is specified:
译:
如果集群的配置文件不再使用了,那么集群的profile就可以删除。这是一个profile敏感的命名-如果没有profile被指定,那么这个命令就会删除掉默认的minikube集群,或者是我们指定的profile。
$ minikube delete
🔥 Deleting "minikube" in virtualbox ...
💀 Removed all traces of the "minikube" cluster.
$ minikube delete -p minibox
🔥 Deleting "minibox" in virtualbox ...
🔥 Deleting "minibox-m02" in virtualbox ...
🔥 Deleting "minibox-m03" in virtualbox ...
💀 Removed all traces of the "minibox" cluster.
For additional commands and usage options please visit the Minikube command line reference.
译:
可以查看上述网页来了解更多命令和使用方法。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)