headerimg
back
europe, backbase

Europe

Netherlands

Amsterdam Utrecht

United Kingdom

Cardiff London
north-america, backbase

North America

Canada

Toronto

Mexico

Mexico City
asia, backbase

Asia

Singapore

Singapore
middle east, backbase

Middle East

UAE

Dubai

Kubernetes in local the easy way: Docker Desktop (on Mac)

LIFE@BACKBASE

Amsterdam London Engineering
Andrés Torres García

What this is 

A step by step tutorial about one of the easiest and most straight forward ways to have a simple single-node Kubernetes cluster running in your local using with Docker Desktop (on Mac).

What this is not

This is not a tutorial or an article about Docker or Kubernetes. There is plenty of literature on those topics on the internet:

A nice online course about Kubernetes from Edx: Introduction to Kubernetes

Docker Desktop download

No Docker Hub Option 

  • If you Don’t have a Docker account already 
  • If you are not planning to publish container images 
  • If you prefer not to share your email address 

Get the macOS Installer .dmg directly here →

https://download.docker.com/mac/stable/Docker.dmg

Here for the Edge version -> https://download.docker.com/mac/edge/Docker.dmg

Docker Hub option

If you use the standard Docker links, for example:

https://www.docker.com/products/docker-desktop

https://hub.docker.com/editions/community/docker-ce-desktop-mac

They will kindly invite you to Sign In into Docker Hub, that will enable the download link, allow you to publish containers to Docker Hub, etc.

You can also do this step after the installation:

Select Sign in /Create Docker ID from the Docker Desktop menu to access your Docker Hub account.

Once logged in, you can access your Docker Hub repositories directly from the Docker Desktop menu.

Docker Desktop installation

  1. Double-click Docker.dmg to open the installer, then drag the Docker icon to the Applications folder.
  2. Cmd + Space and type Docker, you should be able to see the Docker app there, just hit Enter to open it. Docker will start after a few seconds.
  3. Docker will start after a few seconds

You should see a pop up like this:

You can clone the pop-up and click on the Docker icon in the top status bar.

Click on the Docker icon and go to Preferences window as shown below.

Then click on the Kubernetes icon.

You will notice that Kubernetes is not enabled. Simply check the Enable Kubernetes option and then hit the Apply & Restart button as shown below:

This will display a loading spinner while the Kubernetes cluster gets installed.

The installation starts. Please be patient since this could take a while depending on your network.

When the installation is done you should see the same screen:

Note the two messages at the bottom of the window mentioning:

  • Docker is running
  • Kubernetes is running

Congratulations! You now have the following:

  • A standalone Kubernetes server and client, as well as Docker CLI integration.
  • The Kubernetes server is a single-node cluster and is not configurable.

Just an FYI … my About Docker shows the following:


Check our installation

Let us try out a few things to ensure that we can make sense of what has got installed. Execute the following commands in a terminal:

You might have noticed that my server and client versions are different. I am using kubectl from my gCloud SDK tools and Docker for Mac, when it launched the Kubernetes cluster has been able to set the cluster context for the kubectl utility for you. So if we fire the following command:

You can see that the cluster is set to docker-for-desktop.


Tip: In case you switch between different clusters, you can always get back using the following:

$ kubectl config use-context docker-for-desktop

Switched to context “docker-for-desktop”


Let us get some information on the cluster.

Let us check out the nodes in the cluster:


Installing the Kubernetes Dashboard

The next step that we need to do here is to install the Kubernetes Dashboard. We can use the Kubernetes Dashboard YAML that is available and submit the same to the Kubernetes Master as follows:

The Dashboard application will get deployed as a Pod in the kubernetes-dashboard namespace. We can get a list of all our Pods in all namespaces via the following command:

Ensure that the Pod “kubernetes-dashboard-*“ is in Running state. It could take some time to change from ContainerCreating to Running, so be patient.

Once it is in running state, to access Dashboard from your local workstation you must create a secure channel to your Kubernetes cluster.


Kubectl Proxy

kubectl proxy creates a proxy server between your machine and Kubernetes API server. By default, it is only accessible locally (from the machine that started it).

Start a local proxy server.

Once proxy server is started you should be able to access Dashboard from your browser.

Now access you can access Dashboard at:

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

You will see the following screen:

To find a valid token here you have a useful one-liner:

Copy & paste that token into the field and click Sign In to login, the dashboard will show as below:


Let’s Play!

Let us proceed now to running a simple Nginx container to see the whole thing in action:

First things first, setup your command line for productivity:

  1. Kubectl autocomplete

Bashsource <(kubectl completion bash)

Zshsource <(kubectl completion zsh)

     2. Alias for kubectl

Alias to type less (lazy is good) and it will also work with completion:

Now let’s create our first namespace:

To easy work within our new context let’s make it the default:

TIP: create an alias with this, to be able to check contexts easily

so now you can do

or

We are going to use the run command as shown below:

This creates a Pod (https://kubernetes.io/docs/reference/kubectl/conventions/#generators) and we can investigate into the Pod that gets created, which will run the container:

You can see that the STATUS column value is ContainerCreating.

If we wait for a while, the Pod will eventually get created and it will ready as the command below shows:

Now, let us go back to the Dashboard and get to the Pods via the Pods link in the Workloads as shown below:

Click on the Pod and you can get various details on it as given below:

You can see that it has been given some default labels. You can see its IP address. It is part of the node named docker-for-desktop.

There are some interesting links that you will find on this page as shown below, via which you can directly EXEC into the pods or see the logs too.

We could have got the Node and Pod details via a variety of kubectl describe node/pod commands and we can still do that. An example of that is shown below:


Expose a Service

It is time now to expose our basic Nginx deployment as a service. We can use the command shown below:

If we visit the Dashboard at this point and go to the Services section, we can see our nginx service entry.

Alternately, we can use the terminal too, to check it out:

and

You can now visit: localhost:31338 and you will see nginx welcome page:


Conclusion

If you want to have a Kubernetes cluster running in your local in a quick and easy way I hope this blog post helps you with Kubernetes and Docker Desktop for Mac.

Of course, there are other alternatives for running Kubernetes in your local machine, just to mention some of them:

Minikubehttps://github.com/kubernetes/minikube

Minishift (from Openshift): https://github.com/MiniShift/minishift

MicroK8shttps://microk8s.io/

k3shttps://k3s.io/

k3suphttps://github.com/alexellis/k3sup

k3dhttps://github.com/rancher/k3d

kind (kubernetes in Docker): https://kind.sigs.k8s.io/

I also used a lot online resources at the beginning just to play with it and practice some basic concepts, I like specially:

Cookies on Backbase Careers
Backbase uses cookies and related technologies on workatbackbase.com for statistical, preferences and marketing purposes. Google Analytics cookies are anonymized and third-party social media sites may also place cookies that may track your internet behavior. You can adapt your cookie preferences by clicking 'Change options' below. More information on the use of cookies and related technologies on workatbackbase.com may be found in our Privacy and Cookie Policy. By clicking 'Accept' you accept the use of the relevant cookies as described in our Backbase Privacy and Cookie policy.
Necessary
Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.
Preferences
Preference cookies enable a website to remember information that changes the way the website behaves or looks, like your preferred language or the region that you are in.
Statistics
Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.
Marketing
Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.