Kubernetes:
A practical intro
1
Maxim Berge
2
Agenda
3
Part 1:
The product
4
What do we do?
We deliver data about companies
5
How do we get the data?
6
Data sources
7
Part 2
Infrastructure
8
What do we need?
9
What do we need?
10
inoopa.com
Python scripts
Email server
Customer APIs
Databases
Internal dashboards
How do we use computing resources?
11
Security
12
Part 3
Deployment
13
The pain of dependencies
14
Python 3.6.1
Python 3.7.5
Python 3.9.2
Python 3.11.0
…
Web server
Certificate management tool
Firewall tool + rules
Auto scaling tool
Firewall tool + rules
The Solution:
15
Ubuntu 22.0
Python 3.6
FFMPEG 1.0
OpenCV 2.0
CUDA 3.1
Ubuntu 18.0
Python 3.9
FFMPEG 4.0
OpenCV 3.0
CUDA 3.1
CentOS 3.0
Nginx 1.0
Let’s encrypt 2.0
CentOS 3.0
MongoDB 2.4
Dockerfile
16
Docker Image & Containers
17
Docker Image
Docker Containers
Server 1
Docker Containers
Server 2
The pain of Network management
18
Private Subnet
Public Subnet
Users
The Solution:
19
Server
Docker network 1
Docker network 2
Port 80 open
Port 80 open
Server port 8080
Server port 8081
Docker-compose.yaml + swarm
20
The pain of Scaling
21
32 gb RAM
2 CPU
200 gb Storage
8 gb RAM
1 CPU
100 gb Storage
128 gb RAM
4 CPU
2 tb Storage
Vertical Scaling
22
32 -> 64 gb RAM
2 -> 4 CPU
200 gb Storage
8 -> 16 gb RAM
1 -> 2 CPU
100 gb Storage
128 -> 256 gb RAM
4 -> 8 CPU
2 tb Storage
Horizontal Scaling
23
32 gb RAM
2 CPU
200 gb Storage
8 gb RAM
1 CPU
100 gb Storage
128 gb RAM
4 CPU
2 tb Storage
X 3
X 3
X 2
Horizontal Scaling: load balancing
24
8 gb RAM
1 CPU
100 gb Storage
X 3
Horizontal Scaling with
Docker compose
25
docker-compose up --scale my-becode-app=3
The pain of server management
26
Firewall tool + rules
Firewall tool + rules
Firewall tool + rules
32 gb RAM
2 CPU
200 gb Storage
8 gb RAM
1 CPU
100 gb Storage
128 gb RAM
4 CPU
2 tb Storage
The pain of server storage
27
Temporary
Small
Temporary
Small
Persistent (critical)
Big
Summary
28
Questions
29
Ideal solution
30
Part 4
Meet Kubernetes
31
What is Kubernetes?
Kubernetes (K8s) is a system that helps manage and coordinate containers.
If Docker packages your app into portable containers, Kubernetes acts as the boss, ensuring they run smoothly.
It automatically restarts crashed containers, scales them up or down based on demand, handles traffic distribution, and simplifies updates without downtime.
Essentially, Kubernetes takes the hassle out of managing large numbers of containers, keeping your app reliable and efficient.
Kubernetes is what we call a container “orchestrator”
32
Nodes
They are servers (virtual machines)
33
Namespaces
They are networks for resources. It allows to group resources that works together.
A namespace can group multiple resources deployed on multiple nodes.
You can see it as a big bag in which we can put any sort of kubernetes resources.
34
Pods
They groups of containers that can’t work without each others.
35
Deployments
They are groups of resources working together.
You can see them as an App. all the pods are deployed together and you can define rules for scaling.
Ex:
36
Secrets
They are passwords, API keys,...
Anything you would have use a .env file for.
37
Services
Make a resource available across the cluster.
Ex: we have a pod that contains an API, the service will forward all requests to it to the API pod.
Why? Because if we have 1 or 20 pods for a given API, we can just send a request to the service and it will make sure to forward it to the right pod.
Also, it makes sure that we actually create a service for any “feature” we want to expose from a given pod.
38
Persistent volumes
They are virtual hard-drive.
You can create a persistent volume and attach it to one or multiple pods.
You can also define which folder in the pod would be linked to it.
It’s practical because if a pod dies, the volume remain and can be attached to the next pod that will replace it.
If I have an API that stores all images sent by any user in a folder /app/img I can link /app/img to a persistent volume.
39
Ingress
They expose a service to the public internet.
An ingress allows you to link a URL (ex: www.inoopa.com) to a kubernetes service.
That how you can expose an API or a website.
40
Example: my-api
Let’s deploy and expose a simple API!
41
Node: inoopa-prod-1
Pod: my-api-pod
my-api-container
(my-api:latest)
Service: my-api-svc
Ingress: api.inoopa.com
Kubernetes cluster
Example: my-api with scaling
Let’s deploy and expose a simple API and scale it!
42
Node: inoopa-prod-1
Pod: my-api-pod-1
my-api-container
(my-api:latest)
Service: my-api-svc
Ingress: api.inoopa.com
Kubernetes cluster
my-api-container
(my-api:latest)
Pod: my-api-pod-2
Example: my-api with scaling nodes
Let’s deploy and expose a simple API and scale it across multiple nodes!
43
Node: inoopa-prod-1
Pod: my-api-pod-1
my-api-container
(my-api:latest)
Service: my-api-svc
Ingress: api.inoopa.com
Kubernetes cluster
Node: inoopa-prod-2
Pod: my-api-pod-2
my-api-container
(my-api:latest)
Example: m-drive
Let’s deploy and expose an G-drive clone with disk persistence!
44
Node: inoopa-prod-1
Pod: m-drive-pod
m-drive-container
(my-api:latest)
Service: m-drive-svc
Ingress: drive.inoopa.com
Kubernetes cluster
disk-1
Persistent volume claim 1
Example: m-drive with scaling
Let’s deploy and expose a G-drive clone with scaling!
45
Node: inoopa-prod-1
Pod: m-drive-pod-1
m-drive-container
(my-api:latest)
Service: m-drive-svc
Ingress: drive.inoopa.com
Kubernetes cluster
m-drive-PV
m-drive-PVC-1
m-drive-container
(my-api:latest)
Pod: m-drive-pod-2
m-drive-PVC-2
HTTP request
Persistent-volume
Persistent-volume-claim
Persistent-volume-claim
Example: my-website + my-api
Let’s deploy and expose a simple API!
46
Node: inoopa-prod-1
Pod: my-api-pod
my-api-container
(my-api:latest)
Service: my-api-svc
Ingress: api.inoopa.com
Kubernetes cluster
Pod: my-website-pod
my-website-container
(my-api:latest)
Service: my-website-svc
Ingress: www.inoopa.com
Example: my-website + my-api 2
Let’s deploy and expose a simple API!
47
Node: inoopa-prod-1
Pod: my-api-pod
my-api-container
(my-api:latest)
Service: my-api-svc
Kubernetes cluster
Pod: my-website-pod
my-website-container
(my-api:latest)
Service: my-website-svc
Ingress: www.inoopa.com
Example: my-website + my-api + DB
48
Node: inoopa-prod-1
Pod: my-api-pod
my-api-container
(my-api:latest)
Service: my-api-svc
Kubernetes cluster
Pod: my-website-pod
my-website-container
(my-api:latest)
Service: my-website-svc
Ingress: www.inoopa.com
Pod: my-db-pod
my-db-container
(mysql:latest)
Service: my-db-svc
Ingress: api.inoopa.com
Example: my-website + my-api + DB
49
Node: inoopa-prod-1
Pod: my-api-pod
my-api-container
(my-api:latest)
Service: my-api-svc
Kubernetes cluster
Pod: my-website-pod
my-website-container
(my-api:latest)
Service: my-website-svc
Ingress: www.inoopa.com
Pod: my-db-pod
my-db-container
(mysql:latest)
Service: my-db-svc
Ingress: api.inoopa.com
Namespace: data-scraping
Namespace: inoopa-website
Part 5
Interact with
50
With CLI: Kubectl
51
With UI: Lens
52
Part 6
Let’s deploy!
53
Resources
54
Part 7
Your turn!
55
Where do I start?
56
You are learning a new technology, so as with any tech, you first step should always be the official documentation. It’s your lucky day! Kubernetes’ doc is truly well structured and easy to understand. :)
Go on: https://kubernetes.io/docs/tutorials/kubernetes-basics/ and complete the 6 first modules.
You will learn to:
Last advices
57
Kubernetes is a huge rabbit hole. We only scratched the surface today. There is way more vocabulary, concepts, tools, feature,...
Don’t try to understand or read about everything, you will lose yourself and feel like you are not learning anything concrete.
The best way to learn it is to get your hands dirty. Run it locally, deploy a single API, scale it, add another API/DB/website/… that connects to it. Wrap that in a namespace, add a persistent disk, wrap all of that in a deployment… Go step by step. Instead of learning for the sake of it, start with a problem you want to solve. For ex: deploy a complete application. Start with the first block, as you encounter issues, miss a feature, grab the concepts one by one. It will make more sense.
And remember, learning this kind of things takes time, like a lot. You don’t need to know everything to be able to take advantage of the tool! ;)
Questions
58