This article describes different ways to deploy Kubernetes locally to emulate what you would do in a real cloud on your local machine. Running Kubernetes locally can be helpful to save costs, to use portions for CI/CD on your cloud-native applications, and to address situations when you don't have reliable internet access and want to do "real" work.
This article walks through the following technologies:
Install Kubernetes from scratch on a local machine
Note that these approaches worked as of April 2022 when I last updated this article, but this stuff moves fast! By the time you read my advice, there might be additional options for running Kubernetes locally.
Prerequisites
Before you go any farther, I strongly suggest a machine with at least 8 gigs of RAM. Some of the following options are based on virtual machines (VMs), modern operating systems require at least 4 GB of RAM before issues can arise. Having 8 GB of RAM allows for options such as VirtualBox to get enough resources to be able to do more then the bare minimum.
Then, you might as well install kubectl on your local machine. It's the canonical way to interface with any Kubernetes cluster, and your local instance is no different. I will say that you could call directly to the API, but I only suggest doing this if you have a specific reason.
minikube
minikube is the de facto entry point for most people learning about or figuring out how to run Kubernetes on a local machine. I've even heard of some people using minikube to run dev or QA environments on shared VMs on clouds. It feels a lot like the old DevStack options back in the OpenStack days. Honestly, minikube has echos of it, and I think it's probably the best analogy.
Just as any seasoned veteran of the OpenStack ecosystem would say, DevStack is designed for a specific use case, and that's how minikube is targeted too. minikube was and is the answer to the question "What is the fastest way I can get Kubernetes running on my laptop?" and it succeeds at this goal.
However, you should note that it's only one worker node and one machine with relays on VirtualBox or similar for virtualization, and it has only 2 GB of RAM by default to use. This is all but a toy. You can run your typical commands against it, but you can't run anything that isn't stock Kubernetes.
So how do you change this? You can run minikube with a couple other options to give it more resources on start time.
Luckily, you have some commands you can run!
minikube --cpus 2 --memory 4024 start
Show more
The previous command gives your minikube instance two virtual CPUs and 4 GB of RAM. This change should allow you to do more with it, such as install Istio, but not much more. If you want to create or test something closer to your production instance, you should give it more resources. That's up to your restrictions and specific situation.
After you are done working with the instance, I suggest either shutting it down or deleting it completely with the following command:
minikube stop
Show more
If you plan to walk away from your local computer or you don't need the pods you are running for long term, now is a good opportunity to run the following delete command on the VM that is running your Kubernetes cluster, so it doesn't take up unneeded resources:
minikube delete
Show more
If you installed kubectl, you didn't have to export anything or change any configuration around. From what I understand, that behavior is by design. kubectl defaults to the local host that minikube runs on, which allows for a small, but valuable, positive user experience (UX) situation.
MicroK8s
When I first wrote this article in 2019, microk8s was a relatively newcomer to the space. It's supported by Canonical, the company behind Ubuntu. MicroK8s is a simple snap installation, such as the following command:
snap install microk8s --classic
Show more
Obviously, if you don't have Snap, you're out of luck, but if you can swing it, Snap is a way to get a Kubernetes cluster up and running extremely quickly. One oddity with the system is that every command is prefixed. Take a look at the following example:
microk8s.kubectl get nodes
Show more
The huge advantage is you don't have to mess with your KUBECONFIG to talk to your local cluster, but if you are a longtime user of Kubernetes, you must retrain your muscle memory. Take a look at the MicroK8s docs and play around with it.
K3s
When I first wrote this article in 2019, K3s was the newest way to get Kubernetes cluster on a local machine. Originally supported by Rancher Labs, K3s was accepted into the Cloud Native Computing Foundation in 2020 and is currently at the Sandbox project maturity level. I thought it had huge promise. To quote the GitHub page: "Lightweight Kubernetes. Production ready, easy to install, half the memory, all in a binary less than 100 MB."
That's extremely impressive. But it's designed for a specific use case — not for the original statement of running a Kubernetes cluster on your laptop. It's designed for small environments, such as IoT or edge computing. If you have a smaller environment, it's worth checking out.
Install Kubernetes from scratch on a local machine
Ok, so you arrived at this point. Maybe nothing fit your use case, or you are entertained by my writing style and can't stop reading.
Installing Kubernetes from scratch on a local machine is a very specific use case. If you came here to spin up Kubernetes from scratch on your local machine, first of all, I salute you. Second of all...wow. There are many packaged ways to do what you're trying to do, and this approach will only cause heartache.
I'm assuming you have experience going through and editing Kubernetes the hard way to work on your cloud of choice. Then you took and ran it locally on a VM, and now you want bring it to your local development environment.
You might want to run the most recent releases of Kubernetes, and have no trouble figuring out what's going wrong when your application has trouble. You, yes you, are unique. This entire article was not aimed at you, and maybe it opened your eyes to something you haven't thought of. But in general, you are a pioneer on your own boat. May the wind always be at your back. Have fun!
Final thoughts
Hopefully, you can see there are a wide variety of options available for running Kubernetes locally. The crazy part is that this article is only as accurate as my note at the top of the document. Kubernetes is moving fast and becoming the way to run cloud-native applications, but running it without a cloud can be tricky.
Most of the options I mentioned here hit most use cases. You need to do your homework to see what fits your situation the best. Standardize on something, which helps your teams become more successful when they all use the same base wrapper around this amazing technology.
About cookies on this siteOur websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising.For more information, please review your cookie preferences options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.