Kubernetes Basics

Introduction

In this post, we will start with the basics of kubernetes, some terminologies and basic building blocks of its infrastructural bits and the workload objects.

We will also learn basics of kubernetes cluster and will also look at kubectl for cluster management.

For this post, I am assuming that you are already familiar with Docker and running containers from docker images. There are great many tutorials online if you are new to docker. I also have written a book on this topic, which you can read to learn docker basics.

Kubernetes (aka k8s) is all about running and orchestrating containerized apps. It is an open source platform from google. It is a system to manage automating deployments, scaling and management of containerized apps.

On a high level, we will have kubernetes cluster and we will also have a tool kubectl which we will use to manage and communicate with cluster.

Some of key features of kubernetes to help with containerized apps are as follows:

  • Service Discovery/Load Balancing
  • Storage Orchestration
  • Automated Rollouts/Rollbacks
  • Self Healing
  • Secret Areas and Configurations Management
  • Horizontal Scaling of containers

Kubernetes Cluster

A Kubernetes cluster is made of masters and nodes.

Masters ran the control-plane which is basically the brains of the cluster, nodes are where we run our Apps.

Masters

Masters expose an API via an API Server. There is also a cluster-store where state of the cluster and apps are stored. There are also schedulers (which assign work) and controllers (watch loops) on the masters.

Nodes

Nodes, typically consists of:

  • Kubelet (node agent): Responsible for cluster membership and it does all of the talking with the API server.
  • Container-runtime: deals with OS and start/stop and other containers operations.
  • kubeproxy: Handles networking.

Pods, Services and Deployments

Masters and Nodes are the infrastructral bits of the kubernetes, then we also have workload objects such as:

  • Pods
  • Services
  • Deployments

Pod is the atomic unit of scheduling in kubernetes. Deployment brings scaling, self-healing, updates and rollbacks capabilities. Services bring stable networking for pods, such as reliable IP Address and DNS Name.

This is very high level introduction of kubernetes and its various infrastructrual and workload bits. We will come back to these topics in more details in later posts, but lets see how to quickly get started with kubernetes.

Installing Kubectl

As mentioned before, kubectl is kubernetes command line tool. Its a program you can run on your laptop and access and manage your kubernetes clusters.

If it is not already installed on your system, then based on your operating system, you can find instructions about how to install kubectl from official website on this link.

I will however show you how to install it on windows machine.First, we can use powershell’s install-script command to acquire the script for kubectl by executing following command:

Install-script -Name 'install-kubectl' -Scope CurrentUser -Force

It may prompt to install NuGet package as well as shown below:

Once above mentioned command execution completes, we can use the following command to execute the previously acquired install-kubectl script:

install-kubectl.ps1 c:\kubectl

once this completes, you may see screen like below:

Now, we can verify the installation by using following command:

kubectl version --short

and you will see output similar to following:

This means that kubectl tool is installed and working.

Getting Kubernetes

For testing and learning purposes, you can install kubernetes on your laptop. There are many options to do so, however the easiest is via Docker For Desktop installer. Once docker is installed, you can open the Settings windows and Enable Kubernetes as shown below:

It will download some items from internet and will be ready in few minutes.

Also, check the kubernetes menu option by clicking docker icon in the system tray:

After Kubernetes is enabled we can execute the kubectl version command again, we will see output similar to following windows:

This indicates that kubectl and kubernetes are properly setup on our machine.

Some kubectl commands and Alias

kubectl culster-info           //View cluster
kubectl get info               //get info about all resources pods etc

We can also alias kubectl command by executing following command via powershell:

Set-Alias -Name k -Value kubectl

Now we can use this alias for typing commands as shown below:

Summary

In this post, we had a very high level overview of kubernetes and its building blocks. We also installed kubectl, its command line tool and learn one way to get kubernetes on laptop via docker desktop software.

Let me know if you have some comments or questions. Till next time, Happy Coding.

My Recent Books