Getting Started with Docker Kubernetes on Mac

Getting Started with Docker Kubernetes on Mac

Docker & Kubernetes

Today I am going to walk you through how you can set up your Mac with Docker and Kubernetes (K8S) and play with these technologies.

Installing Docker 

We will use Docker community edition available directly from Docker website here. Pretty  easy from here, just download the .dmg file and click on the same to initiate installation. Any available latest Docker version will work for you , in my case I have used 18.06.1-ce-mac73 as shown below. 

About Docker 

When you click on the .dmg file, it will open up a pop up window with Docker icon and a directional arrow towards Applications, similar to below image. You just need to drag and drop the Docker icon in your Mac’s Applications folder which is available in your left panel of Finder window.

Installing to Mac

It will take a while , minutes! , then you are done. You will find a docker icon in top Mac menu bar and will see below context menu upon Clicking up on it.

Initial Docker Context menu

Now it is time to explore few docker commands. Kindly note, this article is not for explaining Docker concepts instead I will be only showing few useful docker commands so you can start the ball rolling. So, let’s begin…

Docker commands

Very first, try “docker version”, you will find below result , version may be different for your case. You may notice that there are two parts, Client and Server.  Most of the time both the versions are same, however you may customize your server or client version with advance mode.

Docker version 

If above command runs smoothly, your installation is successful. Though your Docker context menu should also show accordingly. Now, let’s try few other commands like “docker info” , “docker images”, “docker ps” etc. Later two will not give you any input as you have just started with Docker and there is no images or containers available in your local system. “docker info” will display lots of metadata information in your screen, I encourage you to go through them and try to understand the information.

Docker info

Let’s now run your first dockerized application and start your docker journey with famous hello-world application. Interesting part is that someone has already developed hello-world docker image and uploaded to Docker Hub image registry for you. Thus, you do not need to create the app or image by yourself, docker will automatically download the docker image from the Docker Hub registry if the image is not available in your local. You have already seen that there is no image in your local registry from “docker images” command before. Now try to execute “docker run hello-world” and see what happens. You will see following output.

Running hello-world

Notice the first line, ‘unable to find image ‘hello-world:latest’ locally’ then it is pulling docker image file layer and checking checksum signature and run the image as Docker container in your local system. “Hello from Docker” is the good sign that your ‘hello-world ‘ docker container ran successfully and displayed the result.

Better to Sign in

Okay ! now we are done with setting up Docker and Docker playground is open for you. Before moving ahead to how to set up Kubernetes , let me advise you to create a Docker Hub account from here to have a smooth experience going forward. You will be able to leverage full potential of publicizing your work through Docker hub. After creating your account you can Sign in to your account from Sign in option in Docker context menu as shown below. This will enable “Repositories” option and you will be able to access all the images available to your account. You can also smoothly upload any local images from your system to your Docker Hub account easily.

Docker Sign in option

Enabling Kubernetes

Let’s move on to enabling Kubernetes on you Mac. Click on “Preferences” option from your Docker context menu as shown above. You will get following screen.

Kubernetes option

Now go to Kebernetes tab and enable that as shown below. You may also enable “System Containers” option , but you it is not absolutely required for now. Don’t forget to click on “Apply” button 😉 As soon as you click, it will display a text “Kuberrnetes is starting …”. It will take a while but you can check status from Docker context menu afterwards. First time, it downloads all the required binaries from internet. When Kubernetes is ready , you will see following screen. Note, you can also opt for Swarm orchestration technology which is introduced by Docker where Google has launched Kubernetes orchestration mechanism. 

Enabling Kubernetes

You can see that both Docker and Kubernetes are in running state. You will also see number of images have been downloaded if you fire docker images command.

Docker images

Kubernetes CLI

Now, let’s verify how our installation works and get familiar with various Kubernetes command line interface a.k.a. kubectl CLI. Let’s start with knowing the version of kubectl

Docker CLI info

As you can see that both kubectl client and server versions are 1.10.3, however you can also have different versions with advance mode if you want to play with different types of orchestration servers.

Firing only “kubectl” will give you list of possible kubectl options to perform different actions with Kubernetes. I encourage you to explore them eventually after this getting started tutorial.

Next command you can try with is “kubectl cluster-info” which will display cluster. information with current context in your systems. To check the current context Kubernetes cluster name, you can run following command, in this case, current cluster context is docker-for-desktop

Kubectl current context

Introducing K8S

However, note that you will not be directly able to access these URLs. If you try to access those URLs , you will receive valid JSON response but with failure message from Kubernetes. To access Kubernetes Dashboard to have meaningful user interface to access all Kubernetes features, we need to install Kubernetes Dashboard. It is basically available as Docker container , hence we will create a Kubernetes pod using a predefined YAML deployment descriptor as shown below. Note, if you want to know cluster name and its associated nodes, I leave up to you to play with commands like “kubectl config get-clusters” & “kubectl get nodes” etc.

Installing Kubernetes Dashboard

When Kubernetes Dashboard server is running, you can access the dashboard by using following URL in a browser

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

A pop up window will be displayed with following options, however you can click on skip for now. We will discuss about kubeconfig and Token based AUTH mechanism in different blog. This will give you admin access to the dashboard for making changes via dashboard only. 

Login page for Kubernetes Dashboard

Skipping this option will take you to the following Kubernetes dashboard. You will find many menu options in left side to explore different features from dashboard. However, note that every information can also be accessed via kubectl CLI. Dashboard gives you a better visualization who loves UI. Notice that you have logged in as a Guest. 

Kubernetes Dashboard

If you like to sign in with valid user credential, you can follow below steps. First you need to sign in from upper right corner profile icon. You will get same login pop up window again. Choose Token option and enter the TOKEN. Wait .. how to get the token :). Use following commands.

Exploring Kuebernetes Secrets

Look for kubernetes-dashboard-token secret and copy the name from the above list. Run following command with same secret name

Profile Token

Now copy the token string correctly (exclude token:  at the beginning and ca.crt:  1025 bytes at the end). Paste the token in to log in screen with Token option selected.

Signing with Token

Now, if you click on  then you will be authenticated and will be able to perform few additional steps e.g. accessing settings. But, don’t worry about this now. Just explore the UI and available options to have some familiarity. 

You can refer below documentation URL for more detail about Kuebrenetes dashboard. 

https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/

Let’s do something else that is not there in the documentation. After following below steps , you will have basic understanding of Kubernetes dashboard and commands as well. You can click on “Namespaces” and “Nodes” link from left panel to know about the existing clusters “docker-for-desktop-cluster”. 

Additionally, if you change the namespace from left panel to “kube-system” , you may see following screen with nice detail .

Kube-system namespace detail

Click on “Workloads” from left menu. You will find nothing. Therefore, we will create some workload by using kubectl commands and try to understand how Dashboard changes. You can also add workload from dashboard.

We will use nginx web server/load balancer and deploy on Kubernetes cluster as a pod. Let’s do it with following command

kubectl run hello-nginx –image=nginx –port=80
deployment.apps “hello-nginx” created

Also run

$ kubectl get pods
NAME                           READY     STATUS    RESTARTS   AGE
hello-nginx-6f9f4fc7dd-wgq7d   1/1       Running   0          9m

You can also check this from Dashboard. Please click on “Pods” & “Deployments” menu option sequentially.

Pods from Dashboard

If you click on displayed name (clickable) of each resource type , you will find more information about the same. I encourage you to explore further.

Also look for different new options available on top right corner of each page right. You can scale the deployment/pods , view logs of a pod etc.

Trying additional K8S Commands

You can also execute following commands to get more and more information through kubectl CLI. I encourage you to do these by yourself and discover many new things.

$ kubectl get deployment
NAME          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
hello-nginx   1         1         1            1           29m

$ kubectl expose deployment hello-nginx –type=NodePort
service “hello-nginx” exposed

kubectl get services
NAME          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
hello-nginx   NodePort    10.110.126.112   <none>        80:30017/TCP   9s
kubernetes    ClusterIP   10.96.0.1        <none>        443/TCP        3d

$ kubectl describe service hello-nginx
Name:                     hello-nginx
Namespace:                default
Labels:                   run=hello-nginx
Annotations:              <none>
Selector:                 run=hello-nginx
Type:                     NodePort
IP:                       10.110.126.112
LoadBalancer Ingress:     localhost
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30017/TCP
Endpoints:                10.1.0.13:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

Conclusion

Now, I leave up to you to explore further and let me know in comment section if you find this interesting or if you need any technical clarification. I shall try to respond as soon as I see them. You can also suggest me whether if you want any amendment in this blog. 

Let me know if you want to have Getting Started on any other technical  topic, I shall right away present the same within a week.

Author: Dhrubo

I am passionate about sharing Knowledge , Information and wisdom what ever way is possible. This is small contribution to our society from my part. I am a Programmer and love to architect and modernize IT infrastructure / solution / applications for my clients. I am sharing my experience what I have gained so far via CTT and will keep doing so in regular basis. This is the whole purpose of founding this Knowledge Center for Cloud Technologies.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.