Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Get Started on The Path to Kubernetes Expertise

DZone 's Guide to

How to Get Started on The Path to Kubernetes Expertise

From Minikube and Micro8s to Docker on both Windows and Mac, take a look at this guide to getting started with Kubernetes clusters.

· Cloud Zone ·
Free Resource

Image title


Introduction

No doubt Kubernetes is hot right now. However, setting up a Kubernetes cluster is challenging even for the most technical users. But with recent developments in the Kubernetes space, users now have more options to explore and run Kubernetes on their local machines. These new developments now make it easier for users to evaluate, play, and test Kubernetes.

Three years ago, Kubernetes released Minikube, a standalone tool that runs a single node cluster inside a Virtual Machine (VM) which allowed users to explore and try out Kubernetes on their local laptops. Today, there are many options for users looking to explore Kubernetes.

Windows Docker Desktop

In July of 2018, Docker added Kubernetes into the Docker Desktop for both Mac and Windows Desktop. With a few UI clicks, Docker users were able to deploy a single node cluster development environment.

Later, in December of 2018, Canonical announced a snap package of the MicroK8s install package for the widespread Ubuntu distribution. With a simple one-line command, Ubuntu users can instantly deploy a K8s appliance.

And when it comes down to running Kubernetes in production, in the early 2019, Gravitational has released a radically simple way to create and manage Kuberntetes clusters, which is based on immutable cluster image files instead of traditional way of relying on configuration files.

In this article, we are going to go over all the different options that make it easier-than-before to run Kubernetes on your local computer for development. These single-node installations are not recommended for production deployment. With that caveat, let’s jump into Kubernetes.

Minikube vs. Docker Desktop vs. MicroK8s vs. Others

The oldest of the pack is Minikube. Developed by Kubernetes, it has the broadest support of all three operating systems – Windows, MacOS, and Linux.

Docker Desktop for Mac/Windows now ships with a bundled Kubernetes. This setup is geared for those who are already working with Docker and Docker Compose. It is the most straightforward setup with a single click. However, there are some caveats. The Kubernetes version is tightly coupled with the Docker versions. For example, Docker 18.09 comes with Kubernetes v1.10.11. If you want K8s v1.13, you would need to switch to an edge channel (non-stable) release of Docker.


Another issue that affects Windows users is the fact Desktop Docker requires a professional or enterprise version of Windows 10. If you are using Windows 10 Home edition, you are out of luck (or you can upgrade for $99). For Windows home users, Minikube with VirtualBox may be your only choice.

For Linux users, MicroK8s is a popular choice. Similar to Minikube, it comes bundled with ready-to-go add-ons that simplify setting up a cluster. Those add-ons include Istio, a private image registry, metric server, Prometheus/Grafana, Fluentd, and Jaeger. Out of the box, you can have a K8s cluster with an image registry, an Istio service mesh, node monitoring, and even a popular microservice application tracer, Jaeger. If you want to deploy GPU accelerated machine learning applications, Microk8s include GPU passthrough for CUDA workflows. It can also run in Windows and MacOS using another tool called multipass.

There are other projects such as K3d, Kind, K3s, and minishift. However, we will only concentrate on the popular three listed above.

Lastly, there is Kubeadm. Kubeadm is the official tool to create single and multimode clusters. It provides the manual way of managing and creating Kubernetes cluster which requires some expertise.

Which One to Install

Before we begin, you will need to be familiar with kubectl.

kubectl is the CLI command line tool for running commands against any Kubernetes clusters.

kubectl will come packaged with the systems we will discuss.

Docker Desktop

If you are a Mac or Windows user, Minikube or Docker Desktop (DD) are your two primary choices. Desktop for Docker will probably satisfy the majority of users. With a few clicks, your single node cluster is ready-to-go.

Windows Docker Desktop


Mac Docker Desktop


Docker Desktop will install a bare-bones K8s cluster. It doesn’t even come with a dashboard. The primary appeal of Docker Desktop is the built-in stack deployment.

If you have a relatively simple Docker Compose file, you can run:

docker stack deploy --orchestrator=kubernetes -c docker-compose.yml mynew_k8deploy


Or, you can toggle Kubernetes as the default stack in the preferences.

Keep in mind, Compose-on-Kubernetes transition isn’t always perfect. Some stacks will require some reworking to deploy properly. For example, complex Docker Compose files with environment variables, and local volumes don’t always translate.

However, this is the beginning and a good start. This feature is available as open source for K8s.

Another great feature of Docker Desktop is the graphical ability to switch context. Context gives users the ability to change K8s clusters. The feature comes in handy when you need to connect to local, staging, and production K8s environments.

If you are a Windows 10 Home user, you don’t get to use Docker Desktop and will have to choose another option.

Microk8s

For Linux users, there are many options, but Microk8s is the easiest to set up. Furthermore, it has a significant advantage in the fact it does not require a VM. All services run locally. Native Linux will outperform virtualization. Minikube also has the ability to run without using a VM (vmdriver=none) as well. 

Installation and removal are single one-liners and runs completely isolated. Microk8s only runs on newer Linux distribution that supports Snap (universal package manager). The list of supported distro includes, Arch Linux, CentOs, Debian, Fedora, Linux Mint and Ubuntu.

sudo snap install microk8s --classic


Microk8s installs an upstream Kubernetes with pretty much everything you need.

To avoid any conflicts with existing installs of Kubernetes, Microk8s adds a prefix the kubectl command - microk8s.kubectl .

microk8s.kubectl get nodes
microk8s.kubectl get services


To remove microk8s, you run:

sudo snap remove microk8s


And to get a dashboard up.

microk8s.enable dns dashboard


MicroK8s can work with Mac OSX and Windows with some hacks using multipass.

Minikube

Minikube is the oldest and often first choice solution to start playing with Kubernetes. For Windows and Mac users, Minikube must run in a Virtual Machine. You will need VirtualBox, VMware Fusion, or Hyper-V.

Following the instructions from Kubernetes, the install is rather straightforward.

After the installation, you run minikube start . 

For Linux users who want to run natively without virtualization,

minikube start --vm-driver=none


After you get K8s running:

The first thing you want to do is confirm if your cluster is running by typing in:

kubectl cluster-info



This command will give you information about your cluster. To check the config, run:

kubectl config view


For more vital kubectl commands, here is a cheat sheet.

Dashboard and Access

Depending on which K8s deployment you choose, you want to be able to access your Kubernetes cluster. If you are an expert, you can manage the cluster using the API directly with kubectl. For most users, the dashboard is the way to go.

Minikube is probably the easiest to get up and running without hassle. With a simple Minikube dashboard command,  minikube dashboard , a single node cluster with the dashboard is immediately available.


MicroK8s requires the dashboard add-on to be enabled with microk8s.enable dashboard. 

Docker Desktop requires you to create and add the dashboard service manually.

kubectl apply -f


It is recommended to check the official Git repo for the latest dashboard YAML deployment file.

If you have trouble accessing the dashboard, you may need to enable the Kubernetes proxy with the command  kubectl proxy .

To allow your single node cluster available to other hosts,

kubectl proxy --address 0.0.0.0 --accept-hosts '.*'


Tokens and Authentication

Upon login, you will be prompted to provide credentials for login. If your login screen has a “skip” button, you can go ahead and bypass authentication.


Kubeconfig or Token

Depending on your setup, you can use either kubeconfig or token. The kubeconfig will read the info from ~/.kube/config or C:\Users<Username>.kube\config on Windows.

If you have no credentials, you will need to pull them from the system secrets. Here is a simple command for Linux and OS X users to pull the default secrets:

kubectl -n kube-system describe secret default | grep -E '^token' | cut -f2 -d':' | tr -d '\t' | tr -d " "


The results will print out the token you can use to login to your Kubernetes dashboard.

To inject that token into your kubeconfig, run

kubectl config set-credentials docker-for-desktop --token="$(kubectl -n kube-system describe secret default | grep -E '^token' | cut -f2 -d':' | tr -d '\t' | tr -d ' ')"


Note: set the context name if you are running multiple Kubernetes clusters.

Window users, with Powershell, can run similar commands.

To get token:

kubectl -n kube-system describe secret default | Select-String "token:"


To insert that token into your kubeconfig, place the token into a variable, and insert in your credentials.

Then run:

$TOKEN=((kubectl -n kube-system describe secret default | Select-String "token:") -split " +")[1]


kubectl config set-credentials docker-for-desktop --token="${TOKEN}"


To use kubeconfig, navigate to your .kube/config file. Mac users, use “SHIFT + OPTION +G” and type in "~/.kube/".


Dashboard and Other Services

Depending on your setup, you should start exploring some of the features of your K8s cluster.

By navigating on the left menu bar, you have all the information at your disposal for namespace, deployments, and services.

Here, we have a Microk8s cluster. With a  kubectl cluster-info , we see Grafana is running and simply clicking on the URL; we have the Grafana dashboard.


Deploying a Quick Application

The command will install a tiny NGINX echo app that shows the internal container info.

kubectl run hello-world --image=k8s.gcr.io/echoserver:1.10 --port=8080


To check deployment, run

kubectl get deployments



Or, check in the dashboard


Now, if we want to check that container in our browser, we need to open the container and make it available. There are a few ways to do this, but a port-forward will illustrate how we can view our container.

First, get the pod name through the terminal or via the dashboard. The pod name will have an extended hash like hello-world-84698b5565-57htd

kubectl get pods


Then run the kubectl port-forward  with an external port map to the internal port. Here, I use 9696, which is an open and available port.

kubectl port-forward hello-world-84698b5565-57htd 9696:8080



There you have it. Now pointing to http://localhost:9696 in the browser, you will see the hello-world echo server container running NGINX with some impressive stats.

Installing a real application - Mattermost

Congratulations, you now have a local Kubernetes environment running, so it is time to run your first application. You will want to get an application running with one or more nodes. You can experiment with popular Helm package manager that allows you to run apps like Mattermost, a Slack clone. Follow these simple steps:

Install Helm, then download and run the team-edition.

Helm simplifies installation of many applications with a simple install command like this:

helm install mattermost/mattermost-team-edition \
--set mysql.mysqlUser=sampleUser \
--set mysql.mysqlPassword=samplePassword \


Helm will give you additional information you may need. It even provides additional commands to expose your new application.

Wait a few minutes and voila, you now have an open-source Slack clone for team messaging.


Have in mind, running locally versus production are two different things. Running locally here, we didn’t get into security, persistent storage, and subjects like routing. In production, you want to make sure your passwords to databases are secured with K8 secrets and that users are locked down with ACL (Access Control List) policies. Persistent storage means the data saved by your app will not be erased the next time your pod restarts. Lastly, you want to allow your users to reach your apps through valid URLs versus localhost:8001. Now with this information, go ahead and experiment. As you get familiarized with Kubernetes, you will want to pay attention to some best practices. Lastly, in production, you want to deploy multiple nodes and this how Kubernetes really shines.

Conclusion


Regardless of your role and interest in Kubernetes, these basics will streamline collaboration and make it easier for you to deploy your projects. And today, getting started with Kubernetes is easier than you may have previously thought. There are a growing number of accessible options, and you can have a single node K8s cluster ready for evaluation and development quickly and easily. Even on simple hardware like tablet pictured above, K8s is within reach with a simple click or a few commands.

For additional resources, I recommend you also check out our free Docker, Kubernetes, and Gravity training on GitHub.

Topics:
kubernetes installation ,kubernetes operators ,kubernetes ,container challenges ,container application ,container adoption ,k8s ,cloud

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}