Kubernetes has exploded in popularity, becoming the de facto open-source standard for container orchestration. According to the Cloud Native Computing Foundation‘s 2021 survey, usage of Kubernetes has grown 67% year-over-year, with over 5 million developers now using it.
With Kubernetes, you can easily deploy containerized applications at scale, automate rollouts and rollbacks, and manage application resources efficiently. As a beginner, it can seem daunting to wrap your head around Kubernetes and all its capabilities. But fear not! In this guide, I‘ll walk you through what Kubernetes is, why it‘s useful, and provide hands-on steps for getting started.
What is Kubernetes?
In simple terms, Kubernetes is an open-source system for automating deployment, scaling, and operations of containerized applications. Containers package code and dependencies into portable, isolated processes that can run on any infrastructure.
Kubernetes builds on top of containers to provide a way to coordinate and manage container clusters at scale. While you can run one-off containers using tools like Docker, Kubernetes lets you manage entire fleets of containerized applications across many hosts.
The name "Kubernetes" comes from the Greek word for helmsman or pilot of a ship. This is an apt metaphor, as Kubernetes acts as the helmsman piloting your container fleet – deploying containers onto nodes, monitoring health, scaling and load balancing based on demand, and more.
A Brief History of Kubernetes
Google developed Kubernetes based on their internal container management systems named Borg and Omega. Having run containers at scale for many years, Google decided to build an open-source container management system by partnering with the Linux Foundation to form the Cloud Native Computing Foundation (CNCF).
Kubernetes was first released in 2014, and quickly gained popularity. It is now hosted by the CNCF, with contributions from Google and many other companies and maintainers. Beyond its core functionality, the Kubernetes ecosystem now includes hundreds of tools and integrations developed by the community.
My Take on Kubernetes Benefits
Here are some of the main benefits Kubernetes provides in my opinion:
-
Simplified deployment and scaling – Declare your desired state and let Kubernetes do the work deploying and scaling your containers. No more manual work!
-
Resilience – Kubernetes automatically handles distributing and replicating containers across nodes, restarting failed containers, and rebalancing loads. This provides great redundancy and uptime.
-
Abstracts infrastructure – Kubernetes works on-premise, in the cloud, or anywhere giving a consistent environment. You don‘t need to couple your apps to infrastructure.
-
Development velocity – Engineers spend less time managing environments and deployments and more time building apps. Kubernetes enables a true DevOps approach.
-
Portability – Kubernetes eliminates vendor lock-in, allowing you to migrate applications between on-prem and any cloud. This prevents costly rearchitecting.
-
Robust ecosystem – Kubernetes has a huge community with extensive tools and integrations making it pluggable and extensible.
For these reasons and more, Kubernetes has become the standard for container orchestration and management. Next let‘s look at how Kubernetes is architected.
Kubernetes Architecture
A Kubernetes cluster consists of a control plane that manages worker nodes where containerized applications run.
The main components that make up the control plane are:
-
API Server – The Kubernetes API that acts as the front end for controlling the cluster. Users, cluster components, and external components all communicate with the cluster via the API server. It handles request authentication, validation, and all core Kubernetes objects and operations.
-
etcd – A highly available key-value store that persistently stores the cluster configuration and state. This ensures the cluster state is durable, consistent, and available.
-
Scheduler – Responsible for distributing workloads (pods) across nodes. It looks at resource requirements, hardware constraints, policies, and workload optimization to select the best node for each pod.
-
Controller Manager – Runs core Kubernetes controllers for routine tasks like replicating components, handling node failures, terminating unhealthy pods, etc. Each controller focuses on a specific resource type.
The worker nodes host your containerized applications and cloud-native systems:
-
Kubelet – The agent that runs on every node to communicate with the API server. It handles node management like starting, stopping, and maintaining application containers based on the desired state from the control plane.
-
Container Runtime – The underlying software that runs containers (like Docker, containerd, etc). Kubernetes supports several runtimes.
-
kube-proxy – A network proxy and load balancer that runs on each node implementing Kubernetes networking rules and services.
This architecture allows you to declaratively define your desired state (apps, replicas, networking, etc) and let Kubernetes reconcile the actual state to the desired state. Next let‘s look at how Kubernetes builds upon containers.
Containers and Kubernetes
Containers package code, libraries, and dependencies into an isolated executable package that can run consistently on any infrastructure or OS. Unlike VMs that virtualize an entire hardware stack, containers only virtualize the host OS kernel and share underlying resources.
| Virtual Machines | Containers |
|---|---|
| Emulate a full hardware stack | Share host kernel |
| Allocate dedicated guest OS | Use host OS |
| Heavy (GBs) | Lightweight (MBs) |
| Slow startup | Fast startup |
This makes containers extremely fast, portable, and lightweight. However, running containers at scale comes with many challenges:
- Deploying and distributing containers across multiple hosts
- Scaling up containers to meet demand
- Load balancing traffic between containers
- Handling health monitoring and restarts
- Automating complex tasks like rollouts and rollbacks
- And more!
This is where Kubernetes comes in. Kubernetes handles all these tasks automatically so you don‘t have to. For example:
- You define Deployments that declare the desired state of pods
- Kubernetes handles deploying those pods onto the cluster and monitoring them
- If pods fail or nodes go down, Kubernetes automatically restarts and redistributes them
- The Kubernetes service abstraction provides load balancing between pod replicas
In this way, Kubernetes provides powerful automation on top of basic containerization capabilities.
Installing Kubernetes
To start using Kubernetes you first need access to a Kubernetes cluster. Here are the main options for installing Kubernetes:
Managed Kubernetes Services
The easiest way to get started with Kubernetes is using a fully managed Kubernetes service like:
These handle provisioning and maintaining the Kubernetes cluster for you automatically.
Turnkey On-Prem Solutions
Another option is deploying a Kubernetes distribution designed to be installed on-premises like:
These provide preconfigured bundles to simplify installing Kubernetes yourself.
Custom Cluster
Finally, you can manually install open-source Kubernetes across your machines. This provides the most control but requires the most effort to install and operate. Popular tools include:
- kubeadm – official cluster bootstrapping tool
- Kops – creates and manages clusters on cloud platforms
- Kubernetes Operations (kops) – CLI for installing clusters
The Kubernetes documentation provides detailed instructions for installing Kubernetes across all major environments.
For learning and testing, I recommend using a single node cluster with Minikube.
Installing Minikube
Minikube runs a simple single node Kubernetes cluster inside a VM on your local workstation. This is a great way to test out Kubernetes features and functionality.
Requirements:
- 3+ GB RAM
- VirtualBox or Docker as VM driver
Instructions:
-
Install a hypervisor like VirtualBox
-
Download and install Minikube
-
Open a terminal and enter
minikube start. This will start the Minikube VM and cluster. -
Run
minikube statusto check the cluster status. It should show ‘minikube: Running‘ -
Run
kubectl get nodesto verify you have 1 node configured and ready.
You now have a local Kubernetes cluster up and running using Minikube! Let‘s look at deploying your first application.
Deploying Your First App
To test out your new Kubernetes cluster, you can deploy a simple Hello World application. Here are the steps:
-
Create a file called
hello-minikube.yamland copy this YAML manifest:apiVersion: apps/v1 kind: Deployment metadata: name: hello-minikube labels: app: hello spec: replicas: 1 selector: matchLabels: app: hello template: metadata: labels: app: hello spec: containers: - name: hello image: k8s.gcr.io/echoserver:1.4 ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: hello-minikube labels: app: hello spec: type: NodePort ports: - port: 8080 targetPort: 8080 selector: app: helloThis defines a Deployment and Service for the "hello" app.
-
Apply it via:
kubectl apply -f hello-minikube.yaml -
Check pods:
kubectl get podsand wait for the "hello" pod to be READY. -
Expose the app:
minikube service hello-minikube. This will map the service to a random host port. -
Open the mapped port in your browser and you should see the "Hello World" message!
Congratulations, you‘ve now deployed your first app on Kubernetes using Minikube! Let‘s look at some next steps.
Where to Go From Here
This guide introduced Kubernetes concepts, discussed its benefits, described its architecture, and got you started deploying an app locally using Minikube. Here are some recommendations on where to go next:
-
Do the Kubernetes Basics tutorial – Covers deploying, exploring, exposing, and scaling apps through hands-on examples.
-
Take a free course on Kubernetes basics – Such as Introduction to Kubernetes (edX).
-
Learn Kubernetes objects – Dig deeper into pods, deployments, services, ingress, configmaps, and other objects.
-
Deploy a real application – Follow a guide on packaging and deploying a multi-service distributed application.
-
Explore managing Kubernetes – Learn day-2 operations like metrics gathering, log aggregation, automation, and more.
-
Consider production requirements – Availability, security, networking, storage, disaster recovery, and other concerns.
-
Check the Kubernetes docs – They provide extensive information and guides on all aspects of Kubernetes.
The Kubernetes documentation also has suggestions for what to learn next. Don‘t be overwhelmed by everything Kubernetes can do—start small and work your way up!
Key Takeaways
Here are some of my key takeaways on ramping up with Kubernetes:
-
Kubernetes provides extremely useful automation for deploying and managing containerized distributed apps. It‘s absolutely worth learning.
-
Start by focusing on core resources like pods, deployments, and services. Don‘t get distracted by the many advanced features yet.
-
Minikube is great for experimenting locally. Managed Kubernetes services make it easy to get clusters up quickly in the cloud.
-
Following basic tutorials and deploying your own practice apps is the best way to familiarize yourself with Kubernetes. No amount of reading can replace hands-on experience.
-
As you improve, keep diving deeper into Kubernetes concepts and components. Check the community and ecosystem for helpful resources.
Kubernetes has transformed application development and operations. I hope this guide provided a solid introduction for you to get hands-on experience with containers and Kubernetes. Let me know if you have any other topics you‘d like me to cover!