3 mainstream ways to run Kubernetes locally

About the author
Chris Tozzi, a former reporter and Linux administrator. Strong interest in open source technology, agile infrastructure and network issues. He is currently a senior content editor and a DevOps analyst for Fixate IO.

The main purpose of Kubernetes is to host applications across server clusters through sophisticated load balancing and resource allocation functions. Even if some servers fail, you can ensure that the application runs smoothly. Therefore, in production deployment, multiple servers must be configured for Kubernetes.

However, in some cases, IT administrators or developers may wish to run Kubernetes locally on a PC or laptop. Because the local Kubernetes environment enables developers to quickly test new application code without having to upload it to the production cluster first. For beginners, local Kubernetes is also a good way to learn the container orchestration system without having to bear the complexity and cost of large-scale, multi-server deployment.

Here are three ways to run Kubernetes locally, all of which can be run on a PC or laptop under Windows, Linux, or macOS.

1, Minikube

Minikube is a version of Kubernetes, designed for local deployment. Minikube is developed by the Kubernetes open source community and uses VMs to create a local single-node Kubernetes installation.

The installation of Minikube is very simple, because the Windows, Linux and macOS installers will automatically perform most of the processes, including VM settings. However, please make sure that a VM platform such as Hyper-V, VirtualBox or KVM is installed.

You need to download the latest stable version of Minikube first, and then run it minikube start. The following example is to start Minikube on MacOS:

Use the default HyperKit to run Minikube on MacOS
Use the default HyperKit to run Minikube on MacOS

During startup, the kubeconfig file (~/.kube/config by default) is being updated, and a new context called minikube is being created (later set it as the default context). After Minkube is set up, use the standard Kubernetes command line tool kubectl to interact with the cluster.

The node that is getting minikube
The node that is getting minikube

The main limitation of Minikube is that the local cluster can only contain one node, so it is difficult for a production-level multi-node Kubernetes cluster to perform simulation tests locally.

2 、 MicroK8s

MicroK8s is a Kubernetes release developed by Canonical. Its outstanding feature is rapid and simple deployment, which is very convenient for running Kubernetes locally.

The installation of MicroK8s is very simple on any Linux distribution that supports snap packages. Snap packages is an application packaging framework created by Canonical, mainly for Ubuntu (the company's Linux distribution). Installing MicroK8s on Windows and macOS is also very simple, because the MicroK8s installer of these systems will create an Ubuntu-based VM, and then use snap packages to install MicroK8s on it.

Unlike Minikube, IT administrators or developers can use MicroK8s to create multi-node clusters. If MicroK8s runs on Linux, no VM is even needed. On Windows and macOS, MicroK8s uses a VM framework called Multipass to create VMs for Kubernetes clusters.

# Create a new Ubuntu VM
$ multipass launch --name microk8s --mem 4G
# Install microk8s in the VM through snap
$ multipass exec microk8s -- sudo snap install microk8s --classic

Then we copy the cluster configuration file in a local file:

$ multipass exec microk8s -- sudo microk8s.config > microk8s.yaml

Please note: MicroK8s comes with several binary files, including:

  • microk8s.config: Provide kubectl configuration file for external use

  • microk8s.kubectl: own version of kubectl

Finally, we set the KUBECONFIG environment variable to define the context used by local kubectl:

$ export KUBECONFIG=$PWD/microk8s.yaml

Now, we are ready to use the new MicroK8s single-node cluster.

$ kubectl get nodes
NAME       STATUS   ROLES    AGE     VERSION
microk8s   Ready    <none>   4m48s   v1.16.3

The biggest disadvantage of MicroK8s may be that it is difficult to install on Linux distributions that do not support snap packages.

3 、 K3s

K3s is a lightweight Kubernetes release developed by Rancher Labs, the creator of the industry's most widely used Kubernetes management platform, and has passed CNCF conformance certification. It is designed for production environments and is mainly used for deployment in resource-constrained edge computing scenarios, such as IoT sensors.

However, K3s can also be run locally for Kubernetes testing or development. To do this, first use platforms such as VMware, VirtualBox, or KVM to create at least two VMs on the local system. K3s will not create a VM for you, so you need to do this manually.

Then, install K3s server on one VM, and install K3s agent on another VM. This will create a micro Kubernetes cluster on the local device. For detailed installation steps, please refer to the following articles:

It only takes 5 minutes! You can run k3s on mac

R & D side weapon! k3d+k3s, easily manage local k3s clusters!

Compared with MicroK8s and Minikube, K3s requires more manual work for setup and configuration. However, since K3s is designed for full-scale production, it is the closest option to a production-level server on a PC or laptop.

Original link:

https://searchitoperations.techtarget.com/answer/Evaluate-3-ways-to-run-Kubernetes-locally

Guess you like

Origin blog.csdn.net/qq_42206813/article/details/106114597