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:
- Docker intro from the official docs (always a good place to start): https://docs.docker.com/get-started/
- Kubernetes intro from the official docs: https://kubernetes.io/docs/tutorials/kubernetes-basics/
- Another good one about Docker: https://docker-curriculum.com/
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 →
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:
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
- Double-click Docker.dmg to open the installer, then drag the Docker icon to the Applications folder.
- 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.
- 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 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:
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 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:
- Kubectl autocomplete
source <(kubectl completion bash)
source <(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
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:
You can now visit: localhost:31338 and you will see nginx welcome page:
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:
Minishift (from Openshift): https://github.com/MiniShift/minishift
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:
- Katacoda: They have several scenarios and also a playground cluster with master and one node to play with: https://www.katacoda.com/courses/kubernetes/playground