DEV Community

Raj Aryan
Raj Aryan

Posted on

Kubernetes - A Newbie's Overview

When I first started learning Kubernetes, I thought, "Okay, just another tech buzzword." Then I read that 96% of organisations are either using or evaluating it, and over 5.6 million developers already work with it.

That's when I realised - this thing isn't just a tool, it's the tool.

In this article, I'll explain what Kubernetes is and walk you through some of its basic building blocks. Don't worry - we'll keep it simple. And yes, we're calling it K8s because typing Kubernetes every time feels like a finger workout no one asked for 😁.

What is Kubernetes?

Kubernetes or K8s is an open-source orchestration and cluster management for container-based applications. Think of it as a conductor for an orchestra, but instead of musicians, it's directing containers. It ensures that all the individual containers are running smoothly and working together.

But What's a Container?

A container is a software packaged with its code, libraries, and dependencies into a lightweight, portable unit. Because containers include everything they need, the application runs consistently no matter where it's deployed - on your laptop, in a data center, or in the cloud.

The tool used to build and run containers is called a container engine, and the most popular example is Docker.

Okay, side quest over. Back to Kubernetes 🤿.

Key Workflows of Kubernetes

1. Orchestration

This is the core function. K8s handles the entire lifecycle of containers, including deployment, scaling, and management. It automatically starts, stops, and updates containers as needed.

2. Cluster Management

K8s organizes multiple servers (called "nodes") into a cluster. It then distributes the containers across these nodes to efficiently use resources and provide high availability. If one node fails, K8s automatically moves the containers to another healthy node.

3. Automation

It automates many of the manual processes involved in managing applications. For example, it can automatically restart a failed container, and scale an application up or down based on demand.

Some Basic Components Of Kubernetes

Now that we understand what Kubernetes is and what it actually does, it's time to get into how it does it. Like every piece of sophisticated tech, it has its own jargons. But worry not, I will explain some basic components of K8s which will help you understand how Kubernetes achieves the above mentioned workflows.

1. Pods

  • A Pod is the smallest deployable unit of K8s
  • It is an abstraction over a container - meaning that it is a wrapper over containers. Many containers can reside inside a pod, to be more specific what a container is to docker a pod is to k8s
  • It also provides a shared environment in terms of storage & networking (namespaces and volumes in terms of k8s respectively) to containers
  • Each pod has its own IP address. A pod is ephemeral meaning, it can die and then be recreated and hence assigned a different IP address

2. Deployments/ReplicaSets

  • In K8s abstraction hierarchy, Deployment/ReplicaSets are one level up than pods
  • A deployment represents the desired state and lifecycle of a set of pods. For example, any new deployment can exist with different application.properties (or any config change for that matter like number of replicas wanted or image name, are all examples of configs outside of the application), indicating a desired state of a pod
  • ReplicaSets allow for zero-downtime deployments using rolling update strategies

3. Service

  • A service is an abstraction layer that sits above a group of pods & deployments providing a stable and persistent way to access pods
  • It is of 2 types - external & internal depending upon the communication use-case they fulfill. e.g., a DB - internal service, a Backend Server - external service
  • Services recognise their respective pods with the help of label selectors, if the pod has label x then the service will have a selector of x. (e.g., app: my-app). Think of it like a mail sorting system where letters (traffic) are delivered to the right mailbox (Pod) based on the address label
  • Services are enabled by the kube-proxy component. It watches for new services and manages the network rules on each node, making sure that traffic sent to a service's stable IP address gets correctly routed to the appropriate pods

4. Ingress

  • Ingress is a K8s component that manages external access to your cluster. It handles load balancing, SSL/TLS Termination (handling the complex security handshake so your application can focus on business logic instead of encryption), Path Based Routing (route traffic based on paths /apis, /app), and Name Based Virtual Hosting (single ingress can manage traffic for multiple hostnames). Think of it as the front door of your cluster - it's the gateway through which the external world communicates with your applications
  • Ingress usage required an Ingress Controller which itself is a pod running in the cluster and this is responsible for fulfilling the resource rules. e.g., NGINX, HAProxy etc

5. Config Map & Secrets

  • Config Map & Secrets have the same use case ie of storing your application's configurations (in KV form) outside of your application. So you can simply plug and play without encountering the hassle of rebuilding your application
  • The difference is that Config Map stores your configurations in plain-text format. It's used for non-sensitive data like database URLs. On the other hand, Secrets store your configs in Base-64 encoding. Secrets are used for sensitive credentials like passwords and API keys etc

These are a very few components that K8s offers but knowing these should be enough to start.

Managing Stateful Applications

You must have noticed that all we have talked about so far is concerned with the management of stateless applications (e.g., a Node.js server). Now let's understand how K8s facilitates the management of stateful applications such as databases, messaging queues etc.

Data Storage Components: Volumes

Since pods in K8s are ephemeral, if we run our DB as a normal pod all the data will be lost once the pod dies. To resolve this problem K8s offers another component called volumes.

Volumes attach (or mount, for jargon lovers 🙂‍↔️) a physical storage that exists outside of the pod. It may or may not exist in the same K8s cluster but it is accessible to all the containers belonging to a pod. Note that Volumes are defined at pod level.

Kubernetes manages stateful apps via volumes but how does it renews the image of such apps? With deployments? Of course not. It does so with Stateful Sets.

6. Stateful Sets

Stateful Sets are the counterpart of deployments only but they have more strict rules for managing stateful apps.

Key Characteristics:

  • Stable Network Identity: Each pod in a StatefulSet receives a unique, predictable hostname. For example, a three-replica StatefulSet named web creates pods named web-0, web-1, web-2, with corresponding DNS entries (mapping of hostnames to IP addresses)
  • Persistent Storage: StatefulSets work with PersistentVolumeClaims (PVCs) to ensure each pod maintains its own persistent storage volume. If a pod is recreated, it reconnects to the same storage
  • Ordered Operations: StatefulSets deploy and scale pods in strict sequential order, which is crucial for applications requiring specific startup or shutdown sequences
  • Controlled Updates: Rolling updates occur one pod at a time in reverse order, preventing data corruption in stateful applications

Note: Managing stateful applications in K8s is not an easy task which is why stateful apps such as DBs, Queues are almost always hosted externally on different cloud providers (AWS, GCP, Azure etc).

Conclusion

We've covered the fundamentals of Kubernetes, including its core workflows and essential components that a dev like me encounters daily. While this overview provides a solid foundation, Kubernetes is far more complex and powerful than what we've discussed here.

The beauty of Kubernetes lies in its ability to handle the complexity of modern application deployment while providing developers with powerful abstractions. As you continue your Kubernetes journey, you'll discover advanced features like custom resources, operators, and sophisticated networking configurations.

In upcoming articles, I'll dive deeper into these advanced topics and provide practical examples to help you master Kubernetes. Until then, keep learning and keep growing! 🚀


This article is part of a series on Kubernetes fundamentals. Stay tuned for more in-depth coverage of advanced Kubernetes concepts and practical implementation guides.

Top comments (0)