Basics of Docker and Kubernetes

Abhishek Jaiswal
4 min read2 days ago

--

Source: https://www.docker.com/blog/docker-and-kubernetes/

Docker and Kubernetes work together like a dream team. Docker is the tool that helps us package our applications into containers, while Kubernetes takes care of managing and orchestrating those containers, especially when we need to run them at scale.

A Simple Example: Hosting a Dinner Party

Imagine we’re hosting a dinner party at our home, then the below example help us understand it better

Docker

Docker is like the set of containers we use to prepare and store different parts of the meal. For example:

  • A container for vegetables (with all the veggies, knives, and recipes).
  • A container for meat (with the meat, spices, and grilling tools).
  • A container for desserts (with the cake, frosting, and decorations).

Each container is self-contained and has everything it needs to do its job.

Kubernetes

Kubernetes is like the smart kitchen manager who oversees everything during the dinner party. This manager:

  • Ensures all containers are in the right place at the right time.
  • Reallocates resources if one container needs more help (e.g., if the vegetable container is running late).
  • Replaces a failed container (e.g., if the dessert container burns the cake) without disrupting the party.

How It Works in Real Life

1. Preparing the Meal (Docker)

Before the party, we use Docker to create containers for each part of the meal. Each container has:

  • The ingredients (application code).
  • The tools (libraries and dependencies).
  • The recipe (instructions to run the application).

Example:
We create a container for our web app that includes the code, the web server, and all the libraries it needs to run.

2. Hosting the Dinner Party (Kubernetes)

As the party starts, Kubernetes steps in to manage the containers:

  • It ensures the vegetable container is chopping veggies.
  • It makes sure the meat container is grilling steaks.
  • It keeps an eye on the dessert container to ensure the cake is baking.

If one container finishes early, Kubernetes reassigns its resources to help others.

3. Scaling Up (Kubernetes)

If more guests arrive, Kubernetes automatically scales up by adding more containers to handle the extra workload.

Example:
If our web app gets more traffic, Kubernetes spins up more containers to handle the increased load.

Understanding Docker

Docker is a containerisation platform that lets developers package applications and their dependencies into lightweight, portable containers. These containers include everything the app needs to run, making it easy to deploy across different environments.

Docker Architecture

1. Docker Daemon (dockerd)

  • The background service that manages containers, images, networks, and volumes.
  • It listens for commands and executes them.

2. Docker Client (docker)

  • The command-line tool we use to interact with Docker.
  • We use it to build, run, and manage containers.

3. Docker Images

  • Templates for creating containers.
  • They include the application code, runtime, libraries, and dependencies.
  • Built using a Dockerfile (a set of instructions).

4. Docker Containers

  • Running instances of Docker images.
  • Each container is isolated and has its own filesystem, network, and processes.

5. Docker Registry

  • A storage place for Docker images.
  • Examples: Docker Hub (public) or private registries.

6. Docker Engine

  • The core of Docker, combining the daemon, client, and other tools.
  • It runs and manages containers.
Docker Architecture

Understanding Kubernetes

Kubernetes is an orchestration platform that automates the deployment, scaling, and management of containerised applications. It’s perfect for running distributed systems and microservices

Kubernetes Architecture

1. Master Node

  • The brain of the Kubernetes cluster.
  • It includes:
    - kube-apiserver: The front-end for the Kubernetes API.
    - kube-controller-manager: Manages the state of the cluster (e.g., ensuring the right number of pods are running).
    - kube-scheduler: Assigns pods to nodes based on resources.

2. Node(s)

  • The worker machines that run the containers.
  • Each node has:
    - kubelet: Manages pods and ensures containers are running.
    - kube-proxy: Handles networking and traffic routing.
    - Container Runtime: Runs the containers (e.g., Docker).

3. Pod

  • The smallest unit in Kubernetes.
  • A pod can have one or more containers that share resources (e.g., networking and storage).

4. Deployment

  • Defines how pods should be created, updated, and scaled.
  • Ensures the desired number of pods are running at all times.

5. Service

  • Provides a stable endpoint to access pods.
  • Example: A service can load-balance traffic across multiple pods.

6. Namespace

  • A way to partition resources in a cluster.
  • Useful for isolating teams or projects (e.g., development, production).
Kubernetes Architecture

Why Docker and Kubernetes Work So Well Together

  • Docker makes it easy to package and run applications in containers.
  • Kubernetes ensures those containers are deployed, scaled, and managed efficiently, even across thousands of servers.

Example:

  • We use Docker to create a container for our app.
  • Kubernetes deploys that container across multiple servers, scales it up during traffic spikes, and replaces it if it crashes.

References

  1. https://www.docker.com/resources/kubernetes-and-docker/
  2. https://www.atlassian.com/microservices/microservices-architecture/kubernetes-vs-docker

--

--

No responses yet