Running Kubernetes Locally

In my last post, I covered some basic information about k8s. In this post, I would like to cover how to run k8s locally. I am a Mac guy, so the information provided will be Mac specific. With that said, I will provide links in case you are running a different type of system. Read on to learn more!

To get started, we need a few things. Namely:

  • A virtual environment to run workloads
  • A utility that can deploy k8s in said virtual environment

If you are running HomeBrew on Mac this can be easily accomplished by running:

$ brew install kubectl
$ brew cask install minikube

Next, you will need to start minikube. Kubernetes requires a fair amount of resources. I would recommend 4 CPU and 8 GB of memory if at all possible. This can be done via:

$ minikube --cpus 4 --memory 8192 start --extra-config=kubelet.CAdvisorPort=4194

Now, typing the command can be a bit of a pain so I created an alias as follows:

$ alias mks='minikube --cpus 4 --memory 8192 start --extra-config=kubelet.CAdvisorPort=4194' >>~/.bashrc

It is also worth mentioning that a VM via minikube can be started on a variety of different platforms. For example, if you have VMware Fusion then you can have minikube deploy to Fusion via:

$ minikube --cpus 4 --memory 8192 start --extra-config=kubelet.CAdvisorPort=4194 --vm-driver=vmwarefusion

To confirm everything is working properly, we can list the Kubernetes nodes

$ kubectl get nodes

Given I run kubectl all the time, I have aliased this command as well:

$ alias k=kubectl >>~/.bashrc

If we looks at the pods, we will see nothing is deployed

$ k get pods

With that said, we are now ready to deploy workloads to our local k8s environment. Pretty easy huh? Well, maybe not. In my experience, minikube can be flaky. Here are a few tips:

  • Do not update minikube shortly before you need it (e.g. a presentation) as it could break
  • If commands fail, try running them a second time
  • Check GitHub for issues if you get stuck
  • Consider downgrading minikube version to get things working in worst case

Summary

Kubectl is the primary CLI utility used to interact with a k8s cluster. We successfully deployed k8s locally using minikube. We validated the single host (i.e. node) is running and that no pods exist yet. Overall, great work!

© 2018, Steve Flanders. All rights reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top