本地运行 Kubernetes 的 4 种方法
Kubernetes

> 
> 设置一个本地开发环境，或者直接用这些工具尝试容器编排平台。
> 
> 
> 


![](/data/attachment/album/202011/16/132219hn9q9dszudbdtn35.jpg)


[Kubernetes](https://kubernetes.io/) 是一个开源的容器编排平台。它由 Google 开发，为自动化部署、扩展和管理容器化应用提供了一个开源系统。虽然大多数人在云环境中运行 Kubernetes，但在本地运行 Kubernetes 集群不仅是可能的，它还至少有两个好处：


* 在决定使用 Kubernetes 作为主要平台部署应用之前，你可以快速试用它。
* 在将任何东西推送到公共云之前，你可以将其设置为本地开发环境，从而实现开发环境和生产环境之间的分离。


无论你的情况如何，将本地 Kubernetes 环境设置为你的开发环境都是推荐的选择，因为这种设置可以创建一个安全而敏捷的应用部署流程。


幸运的是，有多个平台可以让你尝试在本地运行 Kubernetes，它们都是开源的，并且都是 [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) 许可。


* [Minikube](https://github.com/kubernetes/minikube) 的主要目标是成为本地 Kubernetes 应用开发的最佳工具，并支持所有适合的 Kubernetes 特性。
* [kind](https://github.com/kubernetes-sigs/kind) 使用 Docker 容器“节点”运行本地 Kubernetes 集群。
* [CodeReady Containers](https://github.com/code-ready/crc)（CRC）用来管理为测试和开发目的优化的本地 OpenShift 4.x 集群。
* [Minishift](https://github.com/minishift/minishift) 通过在虚拟机 （VM） 内运行单节点的 OpenShift 集群，帮助你在本地运行 OpenShift 3.x 集群。


### Minikube


![Minikube](/data/attachment/album/202011/16/132337nukudj3ujbp23pbm.jpg "Minikube")


[Minikube](https://minikube.sigs.k8s.io/docs/) 是在本地计算机上运行 Kubernetes 环境的最知名、最流行的选择。无论你使用什么操作系统，[Minikube 的文档](https://minikube.sigs.k8s.io/docs)都会为你提供一个简单的[安装](https://minikube.sigs.k8s.io/docs/start/)指南。一般来说，安装 Minikube 只需运行两条命令：



```
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-PLATFORM-amd64
$ sudo install minikube-PLATFORM-amd64 /usr/local/bin/minikube

```

Minikube 可在 Linux、macOS 或 Windows 上快速设置本地 Kubernetes 集群，其功能如下：


* 支持最新的 Kubernetes 版本（包括 6 个以前的小版本）
* 跨平台（Linux、macOS、Windows）
* 以虚拟机、容器或裸机的形式部署
* 支持多个容器运行时（CRI-O、containerd、Docker）
* 用于快速推送镜像的 Docker API 端点
* 负载均衡器、文件系统挂载、FeatureGates 和其他高级功能
* 用于轻松安装 Kubernetes 应用的附加组件


因为 Minikube 是一个开源项目，你可以对它的[源代码](https://github.com/kubernetes/minikube)做贡献。


### kind


![kind](/data/attachment/album/202011/16/132341ii5b5z2wp2pvrriu.jpg "kind")


[kind](https://kind.sigs.k8s.io) 的开发者将其描述为“一个使用 Docker 容器‘节点’运行本地 Kubernetes 集群的工具”。它是为测试 Kubernetes 而设计的，但也可能用于本地开发或持续集成。


kind 支持：


* 多节点（包括高可用性）集群
* 从源码构建 Kubernetes 版本
* Make/Bash/Docker 或 Bazel，以及预发布构建
* Linux、MacOS 和 Windows


此外，kind 是一个经过云原生计算基金会（CNCF）认证的 Kubernetes 合规安装程序。因为它是开源的，你可以在它的 GitHub 仓库中找到 kind 的[源码](https://github.com/kubernetes-sigs/kind)。


### CodeReady Container （CRC）


![CodeReady Container](/data/attachment/album/202011/16/132349ah3dgsad3huadz4k.jpg "CodeReady Container")


如果你想在本地尝试最新版本的 OpenShift，可以尝试红帽的 [CodeReady Containers](https://code-ready.github.io/crc) （CRC）。CRC 将一个最小的 OpenShift 4.x 集群带到你的本地计算机上，为开发和测试目的提供一个最小的环境。CRC 主要针对开发者的桌面使用。


你可以在 GitHub 上找到 CodeReady Container 的[源码](https://github.com/code-ready/crc)，也是在 Apache 2.0 许可下提供的。


### Minishift


![Minishift](/data/attachment/album/202011/16/132353ya6o3aajvdanvdno.jpg "Minishift")


[Minishift](https://github.com/minishift/minishift) 项目帮助你在本地用 [OKD](https://www.okd.io/) 在虚拟机内的单节点 OpenShift 集群[运行一个版本的 OpenShift](https://www.redhat.com/sysadmin/kubernetes-cluster-laptop)。你可以用它来[尝试 OpenShift](https://www.redhat.com/sysadmin/learn-openshift-minishift)，或者在你的本地主机上为云开发。


和这个列表中的其他工具一样，Minishift 也是开源的，你可以在 GitHub 上访问它的[源码](https://github.com/minishift/minishift)。


### 为人服务的 Kubernetes


正如你所看到的，有几种方法可以在本地环境中试用 Kubernetes。我有遗漏么？欢迎留言提问或提出建议。




---


via: <https://opensource.com/article/20/11/run-kubernetes-locally>


作者：[Bryant Son](https://opensource.com/users/brson) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
[Kubernetes](https://kubernetes.io/) is an open source orchestration platform for containers. Developed by Google, it offers an open source system for [automating deployment](https://www.kubernetesbyexample.com/en/concept/deployments), scaling, and managing containerized applications. Although most people run Kubernetes in a cloud environment, running a Kubernetes cluster locally is not only possible, it has at least two benefits:

- You can quickly try out Kubernetes before deciding to use it as your primary platform to deploy your application.
- You can set it up as a local development environment before pushing anything to a public cloud, thus allowing separation between the development environment and the production environment.


Setting up a local Kubernetes environment as your development environment is the recommended option, no matter your situation, because this setup can create a safe and agile application-deployment process.

Fortunately, there are multiple platforms that you can try out to run Kubernetes locally, and they are all open source and available under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) license.

[Minikube](https://github.com/kubernetes/minikube)has the primary goals of being the best tool for local Kubernetes application development, and to support all Kubernetes features that fit.[kind](https://github.com/kubernetes-sigs/kind)runs local Kubernetes clusters using Docker container "nodes."[CodeReady Containers](https://github.com/code-ready/crc)(CRC) manages a local OpenShift 4.x cluster optimized for testing and development purposes.[Minishift](https://github.com/minishift/minishift)helps you run OpenShift 3.x clusters locally by running a single-node OpenShift cluster inside a virtual machine (VM).

## Minikube

![Minikube Minikube](https://opensource.com/sites/default/files/uploads/1_minikube.jpg)

(Bryant Son, CC BY-SA 4.0)

[Minikube](https://minikube.sigs.k8s.io/docs/) is the most well-known and popular choice to run a Kubernetes environment on a local computer. No matter what operating system you use, [Minikube's documentation](https://minikube.sigs.k8s.io/docs) offers an easy [installation](https://minikube.sigs.k8s.io/docs/start/) guide for you. Generally, installing Minikube is as simple as running two commands:

```
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-PLATFORM-amd64
$ sudo install minikube-PLATFORM-amd64 /usr/local/bin/minikube
```


Minikube quickly sets up a local Kubernetes cluster on Linux, macOS, or Windows with the following features:

- Supports the latest Kubernetes release (+6 previous minor versions)
- Cross-platform (Linux, macOS, Windows)
- Deploys as a VM, a container, or on bare-metal
- Multiple container runtimes (CRI-O, containerd, Docker)
- Docker API endpoint for blazing-fast image pushes
- LoadBalancer, filesystem mounts, FeatureGates, and other advanced features
- Add-ons for easily installing Kubernetes applications

Because Minikube is an open source project, you can contribute to its [source code](https://github.com/kubernetes/minikube).

## kind

![kind kind](https://opensource.com/sites/default/files/uploads/2_kind.jpg)

(Bryant Son, CC BY-SA 4.0)

[kind](https://kind.sigs.k8s.io)'s developers describe it as "a tool for running local Kubernetes clusters using Docker container 'nodes.'" It was designed for testing Kubernetes but may also be used for local development or continuous integration.

kind supports:

- Multi-node (including high-availability) clusters
- Building Kubernetes release builds from source
- Make/Bash/Docker or Bazel, in addition to pre-published builds
- Linux, macOS, and Windows

In addition, kind is a Cloud Native Computing Foundation (CNCF)-certified conformant Kubernetes installer. Because it's open source, you can find kind's [source code](https://github.com/kubernetes-sigs/kind) in its GitHub repository.

## CodeReady Container (CRC)

![CodeReady Container CodeReady Container](https://opensource.com/sites/default/files/uploads/4_crc.jpg)

(Bryant Son, CC BY-SA 4.0)

If you want to try the latest version of OpenShift locally, try Red Hat [CodeReady Containers](https://code-ready.github.io/crc) (CRC). CRC brings a minimal OpenShift 4.x cluster to your local computer that provides a minimal environment for development and testing purposes. CRC is mainly targeted for use on developers' desktops.

You can find CodeReady Container's [source code](https://github.com/code-ready/crc) on GitHub, also available under the Apache 2.0 license.

## Minishift

![Minishift Minishift](https://opensource.com/sites/default/files/uploads/3_minishift.jpg)

(Bryant Son, CC BY-SA 4.0)

The [Minishift](https://github.com/minishift/minishift) project [helps you run a version of OpenShift](https://www.redhat.com/sysadmin/kubernetes-cluster-laptop) with [OKD](https://www.okd.io/) locally with a single-node OpenShift cluster inside a virtual machine. You can use it to [try OpenShift](https://www.redhat.com/sysadmin/learn-openshift-minishift) or to develop for the cloud, on your local host.

Like the other tools on this list, Minishift is open source, and you can access its [source code](https://github.com/minishift/minishift) on GitHub.

## Kubernetes for the people

As you can see, there are several ways to try out Kubernetes in your local environment. Did I miss anything? Feel free to leave a comment to ask a question or make a suggestion.

## Comments are closed.