A Practical Guide to Kubernetes: Part 1 — Setting Up Your Development Cluster
For the “hands-on” part, you will need a cluster to work on: You will need a Kubernetes cluster, And you will need a Container Registry. Let’s start with picking up a cluster.
Every Saga Has a Beginning
Check out he the table of contents that contains all articles in this series.
In this article series, I want to follow a mixture of providing theoretical knowledge combined with hands-on experience. For the “hands-on” part, you will need a cluster to work on:
- You will need a Kubernetes cluster,
- And you will need a Container Registry.
Let’s start with picking up a cluster.
Choosing a Development Cluster
There are several options you can choose when it comes to creating a development cluster. Here are some:
Using a Local Cluster
You can install Kubernetes locally using Minikube, Kind, or Docker Desktop tools. If you are using Ubuntu, or any Debian for that matter, microk8s is also another popular option that you might try out. These tools typically create a single-node Kubernetes cluster on your local machine, and that’s good enough to learn the concepts and test and develop your applications.
About Docker Desktop
Docker Desktop is famous for its ease of installation. Especially if you are testing things out and are not good at Linux, networking, and shell scripting, it is the fastest way to set up your environment so that you will focus on using Kubernetes instead of the nitty-gritty details about how to deploy a production cluster.
However, if you are (or planning to be) a system administrator, you should look into kubeadm and dive into the rabbit hole a bit further since you will likely be responsible for provisioning, operating, and diagnosing a Kubernetes cluster too.
Another approach would be doing things one at a time. First, install Kubernetes the easy way using Docker Desktop to learn all the fundamental building blocks, and when you feel that you know enough Kubernetes to be dangerous at least, take the heat up a notch and try out kubeadm.
Using a Cloud Kubernetes
Cloud providers such as Amazon Web Services, Google Cloud Platform, and Microsoft Azure offer managed Kubernetes services such as GKE, EKS, and AKS, respectively.
These services enable you to manage Kubernetes easily on the cloud; however, remember that you have to pay for these services too, and most of the time, they are not cheap. However, it is also an excellent way to experience how various cloud providers differ in their Kubernetes offerings. Also, that’s maybe the only way to try out provider-specific add-ons such as EKS Ingress Controllers.
Hosting Your Own Kubernetes
You can deploy a control plane in the cloud if you want to create a more production-like cluster. Again, there are tools like kubeadm or kops to automate the installation and configuration of your cluster.
Obviously, this approach will be more technically involved and a more “hands-on” approach than the former two; however, it will teach you many details that you take for granted in the meantime too.
Which Option Should I Choose
At this point, it is up to you. Deciding which option to choose depends on various factors, such as experience level, budget, and requirements.
If you are learning Kubernetes, I would not focus too much on the implementation details and go ahead with something like Docker Desktop, which is very easy to use and can install a development cluster for you whether you use Mac OS, Windows, or Linux. It is the fastest way to get started.
The second best option for a local development cluster would be Minikube. Docker Desktop and Minikube allow you to learn Kubernetes in a controlled environment without dealing with infrastructure or implementation details.
On the other hand, if you have some experience with Kubernetes, a cloud provider or a self-hosted cluster may be a better option.
Another thing to consider is your budget. Managed Kubernetes services on cloud providers can be expensive. In this case, setting up a self-hosted cluster may be a more cost-effective option. However, keep in mind that self-hosted clusters require more maintenance and configuration. It also depends on what kind of architecture you will test out.
A cloud provider will be an excellent option if you need a lot of compute power and don’t have access to a powerful computer. If you are experienced in servers, Linux, networking, shell scripting, and infrastructure management, in that case, building a production cluster from scratch using kubeadm could be an enjoyable challenge for you to explore Kubernetes internals and see what’s happening under the hood.
Ultimately, your choice will depend on your needs and preferences, how much time you want to allocate setting things up, how much you like debugging and diagnosing systems, and how comfortable you are with Linux shell scripting and networking.
Regardless of your choice, it’s essential to have a development cluster where you can experiment with Kubernetes because the only way to learn Kubernetes is to have hands-on experience with it.
Choosing a Container Registry
In addition to a Kubernetes cluster, you will need a Container Registry to push your container images.
What Is a Container Registry?
Simply put, a container registry is a storage system that holds container images. Container images contain all the necessary components for running an application or service. When it comes to registries, there are a few options that you can pick from.
Using a Cloud Container Registry
There are several registries in the cloud that you can pick from
- Docker Hub is the default container registry for Docker. You can use it as a public registry for free.
- Google Container Registry (GCR) is a private container registry provided by Google Cloud Platform.
- Amazon Elastic Container Registry (ECR) is another private container registry that Amazon Web Services (AWS) provides.
Hosting Your Own Registry
Alternatively, you can host your own container registry too. Two options that work well are Harbor and Quay.
- Harbor is an open-source container registry that provides enterprise-level features such as role-based access control, image replication, vulnerability scanning, and more.
- Quay Quay is also an open-source container registry. It offers both public and private repositories and provides features like vulnerability scanning, build triggers, and image promotion.
Using a Local Development Registry
Or, you can use an OCI-Compliant local registry which does not provide all the bells and whistles of a production-grade registry but is still good enough for local development purposes.
- Minikube, for example, has a built-in registry plugin that you can leverage.
- Similarly, microk8s also has a registry plugin that is effortless to set up.
- Or you can use the docker registry locally with minimal modification to your Docker Desktop configuration.
Using a local registry can be helpful for testing and development purposes. It allows storing and managing your container images within your machine cluster without using an external container registry.
Which Option Should I Choose?
Similar to choosing a Kubernetes cluster, there is no one-size-fits-all answer for choosing a container registry.
Your decision will depend on your specific needs. For example, if you have a local development Kubernetes cluster, a docker registry is a good option for testing and development purposes. Or, if you don’t want to set up a local registry, you can always use Docker Hub, which is freely available for storing public container images.
Putting It All Together
It is impossible to cover all the container registry and Kubernetes control plane combinations outlined in this article. However, and for the purpose of this series, except for certain advanced use cases that will come up much later, a local single-node Kubernetes cluster accompanied by a local container registry will be more than sufficient to do hands-on practice while following the upcoming articles.
I prefer Minikube for my local development and prototyping needs; however, as far as ease of setup goes, nothing beats Docker Desktop.
Installing Docker Desktop
To install Docker Desktop, head to Docker’s home page, download the installer for your operating system, start the installer, and follow the on-screen instructions.
After the installation, you might need to tap and execute the “Docker” binary. Or find it in your Applications folder and launch it, typical of how you launch a desktop application.
Again the steps will vary slightly depending on your operating system, but they will be similar.
Once Docker is up and running, you should see something similar on your menu bar.
The image above is for Mac OS; how and where the menu bar shortcut is placed will depend on your operating system.
Enabling Kubernetes on Docker Desktop
After that, click Dashboard and then the cog icon on the top right, which will open a setting pane.
Next, tap Kubernetes » Enable Kubernetes » Apply and Restart.
After a while, your local Kubernetes cluster will be ready just like that. To test whether Kubernetes is up and running, open a Terminal window and execute
kubectl get node.
kubectl get node
If the command above gives an output similar to the following, congratulations, you have a healthy local Kubernetes cluster to play with.
NAME STATUS ROLES AGE VERSION docker-desktop Ready control-plane 10m v1.25.4
Setting Up Your Local Docker Registry
Thankfully, Docker has an official registry image that you can use for local development needs. Execute the following to set up the registry:
docker run -d -p 5000:5000 --name registry registry:2
And you should be done. Now let’s test it out.
# pull an image: docker pull ubuntu # tag it for the registry: docker image tag ubuntu localhost:5000/my-first-image # push the image to the local registry: docker push localhost:5000/my-first-image # pull the image from the registry: docker pull localhost:5000/my-first-image
If everything went fine, you should see your image in your registry catalog:
The command should output something like this:
Deploying Your First Workload
Now we have everything set up to test things out. Open your favorite text editor and save the following as
Pod.yaml into your working directory.
This is a Pod manifest, that uses the Ubuntu image named
localhost:5000/my-first-image that we just push to our local Docker registry.
Don’t worry about the contents of this file at the moment. In the upcoming articles of this series, you will learn more about Pods and Deployments. Here, we are just testing out if our development environment is in good shape.
After saving it, you can deploy it to your newly-created cluster:
kubectl get po
The output will be similar to the following:
NAME READY STATUS RESTARTS AGE my-ubuntu-pod 1/1 Running 0 35m
References and Further Reading
This section lists tools and technologies mentioned in this article and supplementary learning resources that still need to be covered but are worth exploring.
Local Kubernetes Installations
Tools to Deploy Kubernetes on Production
Cloud Kubernetes Solutions
Cloud Container Registries
Local Container Registries
If you have made it this far, pat yourself on the back.
- You installed Docker and Kubernetes on your system,
- You created a local Docker Registry,
- And you deployed a workload to your Kubernetes cluster using an image you pushed to your local registry.
This will help you explore Kubernetes locally and practice hands-on while we introduce new concepts in the upcoming articles of this series.
And until then… May the source be with you 🦄.
\ \\, \\\,^,.,,. “Zero to Hero” ,;7~((\))`;;,, <zerotohero.dev> ,(@') ;)`))\;;', stay up to date, be curious: learn ) . ),(( ))\;, /;`,,/7),)) )) )\,, (& )` (,((,((;( ))\,