Choosing the right Kubernetes object for deploying workloads in Azure - Part 1
This material has been added to a full eBook, Kubernetes Objects on Microsoft Azure.
This post covers getting started with local development using Kubernetes. It will cover configurations, tools, and common troubleshooting. For an overview of this blog series, use this introductory post.
Getting started with Kubernetes
In a typical development scenario, developers start on their local machines before deploying to a remote cluster, most likely in cloud. This post covers setting up a local Kubernetes development environment.
Setting up Kubernetes locally
To run Kubernetes locally, one needs to install Minikube. It runs a single node Kubernetes cluster on a developer machine/laptop. Kubernetes has the following three dependencies for setting up a local development environment:
- Hypervisor: It enables virtualization, which is the foundation on which all container orchestrators operate, including Kubernetes.
- Kubectl: It is the Kubernetes command -line tool used to manage Kubernetes cluster.
- Minikube: It is a tool that deploys a single node Kubernetes cluster on the developer's machine/laptop.
Enabling a hypervisor
On a Windows 10 local development platform, Hyper-V comes pre-installed and can be turned on as a Windows feature (see Figure 1).
Figure 1. Turning Hyper-V on.
Apart from using the Windows 10 Hyper-V feature, it's possible to use VirtualBox as a hypervisor.
For development platforms other than Windows 10, use one of the hypervisors listed here.
The remainder of this post will use Hyper-V as the hypervisor.
Hyper-V Virtual Switch (Hyper-V only)
In order to use Hyper-V as hypervisor, the additional step of setting up a Virtual Switch is needed. To set up Virtual Switch, follow these instructions –:
- Start Hyper-V Manager. (In the Windows Start menu, type hyper and then select the Hyper-V Manager desktop app).
- Click Virtual Switch Manager.
- Select External as the type of virtual switch.
- Click the Create Virtual Switch button.
- Ensure that the Allow management operating system to share this network adapter checkbox is selected (see Figure 2).
Figure 2: Ensuring the checkbox is selected.
Installing kubectl involves copying the EXE file from here to C:\ (see Figure 3), and then setting it as an environment variable (see Figure 4).
Figure 3. Copying the kubectl EXE file to your C drive.
Figure 4. Setting the file as an environment variable.
Just like kubectl, setting up Minikube (EXE) involves copying the latest Minikube executable from here, renaming the downloaded EXE file to minikube.exe, and adding its path in the system environment variables. In this case, I downloaded and renamed the Minikube file at the same location (C:\) as the kubectl file.
Validating the prerequisite installation
It is easy to verify an installation by running the following two commands. (Figure 5 shows the command is for Minikube, and Figure 6 shows the command for kubectl.)
Figure 5. Running the Minikube command.
Figure 6. Running the kubectl command.
If there is no cluster set up (which won't be for the first time!), ignore the error at Server Version. Next, run the command in Figure 7 to verify the latest version of Kubernetes that is available for installation.
Figure 7. Verifying the latest version of Kubernetes.
In this example, the latest Kubernetes version available for installation is V1.7.0.
Start a local Kubernetes cluster
To start a 1-node Kubernetes cluster using Minikube, use command in Figure 8.
Figure 8. Using Minikube to starting a 1-note Kubernetes cluster.
Note: It uses the prerequisites set up above (especially Hyper-V and Virtual Switch).
After a while, the message in Figure 9 should appear.
Figure 9. The verification message.
Verify the Minikube status by running the command in Figure 10.
Figure 10. Verifying the Minikube status.
Run the two commands in Figure 11 to verify kubectl as well.
Figure 11. Verifying the kubectl status.
If there are deployment issues, follow these steps:
- Ensure that you are running the command prompt in Administrator mode.
- Stop Minikube by running minikube.stop followed by the minikube.delete command.
- Stop and delete the Minikube Virtual Machine in Hyper-V Manager.
- Delete the .kube and .minikube folders in the HOME path (generally found at C:\windows\users\<your-user-id> ).
When running Minikube, use the command in Figure 12 to access its dashboard.
Figure 12. Accessing the dashboard.
A browser window showing the Kubernetes dashboard opens (see Figure 13).
Figure 13. The Kubernetes dashboard.
My next post will cover setting up a Kubernetes cluster in Azure.