Hands On Docker & Kubernetes
2025 Data Science Study Group�An-Che Liang
Quick Video: 100 seconds of Docker
How do we deliver software at scale?
Developer
Ubuntu 22.04
x86-64
Some-Library�1.0.0
Source code
Executable File
Client B
Client C
Client A
Hardware
Software
However, different clients have different machine
Client A
Ubuntu 22.04
x86-64
Some-Library�1.0.0
Executable File
Client B
Windows 10
x86-64
Some-Library�1.0.0
Executable File
Client C
Ubuntu 22.04
SPARC V8
Some-Library�1.3.2
Executable File
Incompatible Hardware
Incompatible Software
Different level of virtualization
Emulated Hardware
Emulated Software
x86-64 (qemu)
SPARC V8
OS, Drivers, Libraries
Emulator
Windows 10
x86-64
Ubuntu 22.04, Drivers, Libraries
Virtual Machine
Windows 10
x86-64
Docker Engine (shared kernel)
Container
Ubuntu 22.04
Win 98
More Efficient
Install Docker
Follow the instructions on the official website to complete the installation. Then, verify it by running the following command: sudo docker run hello-world. You should see output similar to the example below:
Container Life Cycle
Dockerfile
Docker Image
Docker Container
docker build
docker run
Docker Commands
1. FROM – Specifies the base image to use, pulled from a Docker registry (a server that hosts pre-built images). In this example, we use python:3.12-slim.
2. COPY – Copies source code into the Docker image. It's best practice to include only the necessary files to keep the image lightweight.
3. RUN – Executes commands to prepare the environment, such as installing dependencies required for your service to function correctly.
4. ENTRYPOINT – Defines the default command that runs when the container starts, effectively launching your service.
Dockerfile Example
A typical Python FastAPI application
Further Reading
Quick Video: 100 seconds of Kubernetes
11
How do we serve software at scale?
12
Client B
Client C
Client A
x86-64
Your PC
Database
4CPU �8Gb RAM
Supply Chain�Management
Customer Support
The number of customers will scale as your business grows
13
Client B
Client C
Client A
x86-64
Your PC (upgraded)
Database
32CPU �128Gb RAM
Supply Chain�Management
Customer Support
x10
However, single hardware couldn’t scale to infinity
14
Client B
Client C
Client A
x86-64
Does not exist / �Crazy expensive
Database
1024 CPU �1Tb RAM
Supply Chain�Management
Customer Support
x1000
But we could separate our software into different machines
15
Client B
Client C
Client A
x1000
x86-64
Customer�Support
4CPU �8Gb RAM
x86-64
Customer�Support
4CPU �8Gb RAM
x86-64
Supply Chain
Management
4CPU �8Gb RAM
x86-64
Database
4CPU �8Gb RAM
Your company PCs
What if ?
16
All of this translates into increased maintenance costs and the risk of unexpected downtime.
Abstraction between software and hardware �(like an OS that manages multiple computers)
17
Client B
Client C
Client A
x1000?
Kubernetes
Customer�Support
HR (New)
Database
Supply Chain
Management
4CPU �8Gb RAM
4CPU �8Gb RAM
4CPU �8Gb RAM
4CPU �8Gb RAM
16CPU + GPU 32Gb RAM�(Rented from AWS)
Service Team
Infra Team
Managing services at scale
18
Kubernetes ensures the service team never runs out of compute capacity—and frees the infra team from manually shutting down idle machines—by automatically scheduling workloads on any available machine (node).
Source: Kubernetes official website
Managing Kubernetes
19
Install minikube (k8s on your machine), kubectl (terminal for k8s) and k9s (optional, htop for k8s)
Pod
20
A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.
Node
21
Kubernetes runs your workload by placing containers into Pods to run on Nodes. A node may be a virtual or physical machine, depending on the cluster.
Persistent Volumes & Persistent Volume Claims
22
A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. It is a resource in the cluster just like a node is a cluster resource.��Pods access storage by using the claim as a volume. Claims must exist in the same namespace as the Pod using the claim.
Service, ReplicaSet and Deployment
23
In Kubernetes, a Service is a method for exposing a network application that is running as one or more Pods in your cluster. A ReplicaSet's purpose is to maintain a stable set of replica Pods running at any given time.��A Deployment provides declarative updates for Pods and ReplicaSets.
Ingress
24
Make your HTTP (or HTTPS) network service available using a protocol-aware configuration mechanism, that understands web concepts like URIs, hostnames, paths, and more.
Further Reading
25