An Introduction to Kubernetes for Complete Beginners

An Introduction to Kubernetes for Complete Beginners

Understand the architecture of Kubernetes to have a solid understanding of the technology.

This comprehensive guide will teach you all you need to know about Kubernetes in order to get started. This article assumes you're familiar with virtualization and containerization concepts, as well as platforms like Docker. In this article you will learn about the various components involve in Kubernetes. You will also create your first Kubernetes cluster by the end of this article.

What is container orchestration?

With the growth of Microservice architecture in application development, a single application can now contain a large number of separate containers. Kubernetes, is a container orchestration solution that manages these containers and guarantees high availability, scaling, and disaster recovery.

What is Kubernetes?

Google released Kubernetes, an open-source container orchestration technology, in 2014. Kubernetes is a container management and deployment system that works in a variety of environments.

Why Kubernetes?

Assume you are working on a software project for months, and the deadline is approaching. Finally, after a few months, you've completed your project; now it's time to show it to your clients. You zipped the software and sent it over using Google Drive. You get a call after mailing it, saying the client is having trouble executing the programme on his PC. Isn't it aggravating? Containerization comes into play here. You might use a compose file using technologies like Docker and cri-o to declare the dependencies and all the configuration the app will need to run in an isolated environment.The container ensures that your app behaves just as it did on your system. But what if you have numerous containers with multiple dependencies, each of which needs to communicate with the others in order for the software to run smoothly? Only a few containers could be handled by the containerization technologies, and managing a large number of containers would be difficult. So, what's the answer? Here comes Kubernetes.

Kubernetes handles a large number of containers, fault tolerance, rolling out new software versions without affecting existing functionalities, and much more. Kubernetes is the most popular container orchestration technology, with a rapidly developing community.

Kubernetes Components

  • Node: Node is a server in a physical or virtual machine. This is the place where your containers live.

  • Pod: A pod is the smallest unit of Kubernetes. A Pod runs one application container inside itself, it provides an abstraction layer between the container and Kubernetes. Each Pod is assigned its own IP adderess so that they can communicate over that virtual network.

  • Service: A service is a static IP adderess for a pod. If a Pod restarts or crashes the IP adderess assigned to a Pod changes which creates problems in communicating with the Pod using the previous IP adderess that is why Sevice is used to provide a pod with a permanent IP adderess. Service is of two types - External Service: It is used to make our app available to browsers and other networks and Internal Service: It is used to make our other Pod available to our app.

  • Ingress: It is used to route your domain to the IP. The External IP of a Node server looks something like 124.169.34:8080 which is not appropriate for production that is why you will use to route your domain from 'yourapp.com' to the IP. The request first goes to the Ingress then to the Service.

  • ConfigMap: Configuration of the application is stored in ConfigMap. This is used to store the configuration details in central place so that in case of any changes the change has to be made in the ConfigMap and not to every place in the Pods.

  • Secret: The secret in Kubernetes is just like the ConfigMap but it also encrypts the data using third-party apps, that is why it is mostly used to stored sensitive data like credentials.

  • Volumes: Whenver you restart a Pod the existing data on the Node vanishes. Volumes are used for data persistence, it does it so by connecting the Pod storage to a local disk or remote storage.

  • Deployement: It is a blueprint of the Pods. Deployment is used to replicate the Pods in case of any failure. If a Pod dies in the Deployment, other Pod immediatly takes over using the same service.

  • StatefulSet: The StatefulSet is used to replicate statefull apps, the apps which use any database must be created using StatefulSets not Deployments.

Kubernetes Architecture

Kubernetes Architecture

To understand how Kubernetes orchestrate a huge number of containers you need to look at how Kubernetes is architectured. The Kubernetes works in Master/Worker methodology, every Worker Node has a Master node through which we can interact to the pods. Every node is able to run the Pods because each Node must have the three processes:

  • Container Runtime: Since each Pod is a container in itself that is why every Node must have a container runtime. If the Pod has Docker container then the Node must have Docker Runtime installed to run the Pod.

  • Kubelet: It is responsible for the interaction between the Node and the Container. The Kubelet starts the Pod with container inside. Kubelet also assigns the resources to the Pods.

  • Kube Proxy: It is used to for the communication between the Pods, the Kube Proxy makes sure the request to the service goes in the same node and not to any other Pod in another Node, this prevents network overload on the Pods.

Master Node

A master node is responsible to control how the nodes replicated in the cluster and how the new pods get created. The request given to the Nodes first goes through the master node which routes the request to the approapriate node in the cluster. There are four running processes running in the master node.

  • API server: When the client wants to interact with the node using a CLI tool or Dashboard the API server acts as a gateway for the client's request, the request gets passed thorough the API server which then validates the request and then sends it to other processes. It is the only entry point in the cluster.

  • Scheduler: Scheduler in a Kubernetes cluster is responsible to decide where a new Pod in the Nodes should be created after intelligently computing the CPU usage of the available worker nodes. The node which have more resources will be chosen to create a new Pod. After the decision made by the Scheduler the Kubelet recieves the request to start a new Pod in the Node.

  • Controller Manager: The Controller Manager detects any state changes in the Cluster. In case any Pod crashes the Controller Manager detect it and send a request to Scheduler Manager to start a new Pod with the previous state.

  • etcd: It is the cluster brain, a key-value storage where there are details of the avilable resources. The etcd stores all the cluster changes in its storage.

The above processes are absolutely crucial in order to run our Kubernetes cluster properly. These processes makes a cluster robust and fault tolerent. In a real-life scenario there are multiple Master Nodes with multiple worker node under them to facilitate load balancing.

Google Kubernetes Engine

Google Kubernetes Engine is a managed service offered by GCP. You can employ container orchestration in your Cloud with the help of GKE. GKE offers auto-repairs, which means that if a node fails, GKE will automatically repair it using your configuration. It also includes Pod and Cluster Autoscaling, which allows you to scale up the number of instances in response to high demand. It also allows Cloud Logging and Cloud Monitoring to be used.

Creating a Kubernetes cluster using GKE

  • For the introduction you will create your first Kuberneter Cluster in GCP using GKE. To start sign in to your GCP account using your credentials and start a new project.

  • To use GKE, you first need to make sure that the Kuberneter Engine API and Container Registry API is enabled, without this you won't be able to use GKE in your project. Go to the left hand side menu then click on APIs & Services, then search for both the above two APIs and make sure they are enabled.

Kubenetes API enbled

  • Now we are ready to create our Kubernetes Cluster, in your Google Cloud Console, on the top-right side click on the Cloud Shell button which will open up a new Integrated Command Line window at the bottom of the screen.

  • To work with Kubernetes the GKE provide you with gcloud container command line utility.

  • Type the following command in the command line, gcloud container create clusters mycluster --zone us-central-a --num-nodes 2, this command creates a cluster named mycluster in the given zone with two nodes.

  • The creation of the cluster could take a few minutes, after it is done you can verify it by running kubectl version, kubeclt is a Kubernetes cluster command line utility,to mange nodes and pods.

  • You can also view your Kubernetes intance in GCP console, by navigating to Compute Engine and then VM instances.

Conclusion

Kubernetes is a serious technology that should not be used for a project. Kubernetes is used by large corporations all over the world. Kubernetes is trusted by serious businesses. If you're planning to build and launch just an online utility web app, Kubernetes might not be necessary. Kubernetes is for businesses where a second of outage can cost thousands of dollars. That is why, before implementing Kubernetes, you must conduct extensive research. This doesn't mean that you should not learn Kubernetes. The demand for this technology is increasing every day, and there are numerous job opportunites available these days for Kubernetes.

You learnt what problem Kubernetes solves and how it solves it in this article. You also looked at the many components that contribute to Kubernetes' robustness. Then you learned about the technology's architecture, which makes it fault-tolerant and scalable. You also examined the various components of the master node, which is in charge of communicating with all nodes. Then you used Google Cloud Platform's managed service, Google Kubernetes Engine(GKE), to establish your first Kubernetes cluster.

I hope you found this article useful; if so, visit me on Twitter, where I post technology-related content, primarily about web development. Give me a follow if it interests you.