Get Kubernetes running locally on OSX and Windows
Requirements:
For Windows
- Windows 10 Pro (1607 or later)
For OSX
- El Capitan 10.11 +
- Hardware 2010 or newer
With the integration of Kubernetes into the docker engine, local development of Kubernetes based applications has become easier than ever. In this guide, we will cover installing Kubernetes locally and then using the kubectl CLI to install the Kubernetes dashboard onto it.
The first step will be to install the latest edge version of Docker CE for your respective operating system. We are using the edge version because this version currently comes with Kubernetes. Below, I have provided some links you may use to download the Docker CE installer.
Please note, installing Kubernetes on operating systems that do not natively support Linux containers, such as the two operating systems this guide is targeting, will require virtualization to be enabled on your CPU. Doing so will allow the Docker CE installer to create a virtual machine so that your Linux based containers may run in a Linux environment. If virtualization is not already enabled, this can be done through your computer’s BIOS window.
Once you have Docker installed, please right click the docker icon on your toolbar and select Preferences (Settings on Windows). Here you should see a screen similar to below. It will look a little different on Windows, but the same tabs should be on your screen.
This window is very useful, and I encourage you to poke around and see what features it has to offer. For example, under Daemon you can add private repositories and under Advanced you can configure the resources you have allocated to your docker environment. Once you feel like you have managed to absorb the glory of this window, please navigate to the Kubernetes tab you should see on your screen. If you do not see a Kubernetes tab, you may not have installed the edge version of Docker CE. Please uninstall Docker CE and try again using the installers listed previously.
From the Kubernetes tab, please click the Enable Kubernetes check box and select Kubernetes as your default orchestrator. The next step in installing the immensely complicated and intimidating system that is Kubernetes is to click the apply button at the bottom of your screen.
Now you should see the phrase Kubernetes is starting… written somewhere on your screen. Momentarily, your local Docker Engine will provision a fresh, clean Kubernetes cluster for you to play with. Difficult, right?
In the meantime, let’s download a tool that we will use to communicate with the cluster. This tool is called kubectl. It is a command line interface that you can use to apply changes to a Kubernetes cluster, get the state of several different components, pull logs for your running containers, and much more. Later in this guide, we will install a dashboard that can be used to monitor the state of our cluster. Until then, we will use kubectl for this purpose. Below are instructions for installing kubectl.
Instructions for installing kubectl
By the time you are finished installing kubectl, your Kubernetes is starting…icon should be green, and your cluster should be up and running! To test this, try running the following command from your terminal (or PowerShell) window.
kubectl get podNo resources found.
After running the “get pod” command, you should get “No resources found” as a response. If you get anything else, then you may be accessing a different Kubernetes cluster. Fear not, for Docker CE comes with a solution for swapping between Kubernetes clusters. Simply right click the Docker icon on your toolbar and navigate to the Kubernetes drop down menu. Here you need to select the docker-for-desktop context.
Now that we have a functioning Kubernetes cluster, let’s deploy something to it. Kubernetes, by default, ships with no pre-installed dashboard. So, we will be using kubectl to install a community developed Kubernetes dashboard.
Every state change in Kubernetes is made through yaml files. Therefore, we will need a yaml file that defines every configuration necessary to run the Kubernetes dashboard. Conveniently, the community maintains one that we can use here.
In order to install our dashboard using this file, we simply need to execute the following command:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
The following output will let us know that all of our configurations have been applied appropriately
secret "kubernetes-dashboard-certs" created
serviceaccount "kubernetes-dashboard" created
role.rbac.authorization.k8s.io "kubernetes-dashboard-minimal" created
rolebinding.rbac.authorization.k8s.io "kubernetes-dashboard-minimal" created
deployment.apps "kubernetes-dashboard" created
service "kubernetes-dashboard" created
This yaml file will create what is called a ClusterIP type service that exposes our dashboard only within the internal network of the Kubernetes cluster. Therefore, we will need a proxy in order to access it. Luckily for us, kubectl has this feature built in! Simply execute the following command and access the dashboard through the following url.
kubectl proxy
Now, you will be able to access the dashboard here.
You will be prompted for login information. This can be used to enforce fine grained access to Kubernetes resources. Inside of the dashboard, an authenticated user will only have access to the resources his account is able to view/change. For the purposes of this guide, please click the skip button. Now you should see your beautiful dashboard!
We have a fully functioning local Kubernetes cluster with a dashboard to prove it! Now you are well within your power to deploy applications to it; get developing!
For those interested in participating with the community, you are welcome to join the discussion going on at http://slack.k8s.io/
Documentation:
https://kubernetes.io/docs/reference/
https://github.com/kubernetes/dashboard/wiki