1 of 25

Hands On Docker & Kubernetes

2025 Data Science Study Group�An-Che Liang

2 of 25

Quick Video: 100 seconds of Docker

3 of 25

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

4 of 25

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

5 of 25

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

6 of 25

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:

7 of 25

Container Life Cycle

Dockerfile

Docker Image

Docker Container

docker build

docker run

8 of 25

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.

9 of 25

Dockerfile Example

A typical Python FastAPI application

10 of 25

Further Reading

  1. Docker Official Documentation Resources:
    1. Mounting local storage to container: link
    2. Restart policy: link
    3. Resource constraint: link
  2. Choosing the Right Docker Base Image for Your Use Case:
    • PyTorch: link – For deep learning applications.
    • Alpine: link – A minimal Linux distribution optimized for cloud-native applications.
    • Windows 95 (Unofficial): link – An emulator image used to run legacy Windows 95 software.
  3. Optimizing performance:
    • Reducing image size: link
    • Speed up build speed: link

11 of 25

Quick Video: 100 seconds of Kubernetes

11

12 of 25

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

13 of 25

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

14 of 25

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

15 of 25

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

16 of 25

What if ?

16

  1. Every summer our site traffic surges—students are on break, buying seasonal clothes instead of their uniforms—and we need three extra servers to handle the load.
  2. Because our supplier only responds on business days, holiday traffic remains very low, so we don’t require a dedicated server during those periods.
  3. In 2024, one machine overheated and had to be repaired—but the maintenance team didn’t know which services were running on it.

All of this translates into increased maintenance costs and the risk of unexpected downtime.

17 of 25

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

18 of 25

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

19 of 25

Managing Kubernetes

19

Install minikube (k8s on your machine), kubectl (terminal for k8s) and k9s (optional, htop for k8s)

  1. Run kubectl get <resource> prints a table of the most important information about the specified resources.
  2. Run kubectl describe <resource> show details of a specific resource or group of resources.
  3. Run kubectl apply -f <file-definition> to apply changes to the cluster.
  4. Run k9s to view the cluster in GUI.

20 of 25

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.

21 of 25

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.

22 of 25

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.

23 of 25

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.

24 of 25

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.

25 of 25

Further Reading

25

  1. Documentation of Kubernetes (link)
  2. How to manage Kubernetes Applications (all the yaml files)? Helm (link)
  3. How to automatically scale up replica size? Horizontal Pod Autoscaling (link)
  4. Extend custom logic to Kubernetes with Kubernetes Operator (koph)
  5. How to monitor the status of all the pods/deployments/services? �Prometheus (link) and Grafana (link)
  6. How to manage secrets such as access token? HashiCorp Vault (link)
  7. How to automatically sync configs in Git repository with Kubernetes?�ArgoCD (link)