1 of 59

Kubernetes:

A practical intro

1

2 of 59

Maxim Berge

  • Web dev training @Becode
  • AI training @Becode
  • ML Engineer @Fatkion / Metamaze
  • AI coach + infrastructure manager @Becode
  • Chief Technology Officer @Inoopa
  • WebDev / Data Engineer / coach @Freelance

2

/maxim-berge

maxim@inoopa.com

inoopa.com

3 of 59

Agenda

  • Define a product we will work on
  • Define the infrastructure it needs
  • Define how we can deploy it
  • Define what are the pain points
  • Define the possible solutions to these
  • What is Kubernetes?
  • Vocabulary & core concepts
  • Deployments exemples
  • Live demo
  • Your turn

3

4 of 59

Part 1:

The product

4

5 of 59

What do we do?

  • Lead generation
  • Data enrichment
  • Sector studies

We deliver data about companies

5

6 of 59

How do we get the data?

6

7 of 59

Data sources

  • Web scraping (Linkedin, Belgian monitor, Search engines,...)
  • Custom AI models
  • Internal databases

7

8 of 59

Part 2

Infrastructure

8

9 of 59

What do we need?

  • Run code on schedule (web scraping)
  • Store data securely
  • Deliver data (API, Email server,...)
  • Expose a website
  • Expose internal tools only to employees

9

10 of 59

What do we need?

10

inoopa.com

Python scripts

Email server

Customer APIs

Databases

Internal dashboards

11 of 59

How do we use computing resources?

  • Huge resources for a short amount of time
  • Unpredictable workload

11

12 of 59

Security

  • DB should not be exposed on internet
  • Internal tools should not be exposed on internet
  • APIs & public requires secure login
  • Data from a client can’t be access by another one

12

13 of 59

Part 3

Deployment

13

14 of 59

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

15 of 59

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

16 of 59

Dockerfile

16

17 of 59

Docker Image & Containers

17

Docker Image

Docker Containers

Server 1

Docker Containers

Server 2

18 of 59

The pain of Network management

18

Private Subnet

Public Subnet

Users

19 of 59

The Solution:

19

Server

Docker network 1

Docker network 2

Port 80 open

Port 80 open

Server port 8080

Server port 8081

20 of 59

Docker-compose.yaml + swarm

20

21 of 59

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

22 of 59

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

23 of 59

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

24 of 59

Horizontal Scaling: load balancing

24

8 gb RAM

1 CPU

100 gb Storage

X 3

25 of 59

Horizontal Scaling with

Docker compose

25

docker-compose up --scale my-becode-app=3

26 of 59

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

27 of 59

The pain of server storage

27

Temporary

Small

Temporary

Small

Persistent (critical)

Big

28 of 59

Summary

  • Deploying / scaling on multiple machines is hard
  • Managing / securing / optimize multiple machine is time consuming
  • Dependencies are a pain
  • Network management can become complexe
  • Deploying twice the same code can result in different results
  • Docker + docker-compose + docker swarm can help
  • Managing servers remains a pain
  • Storage backup is time consuming

28

29 of 59

Questions

29

30 of 59

Ideal solution

  • Deploy docker containers across multiple machines
  • Integrated network management
  • Creating & destroying new servers based on the load
  • Auto scaling integrated
  • Secrets management
  • Infrastructure As Code
  • Server security / update / configuration done for us
  • Backup / Storage persistence done for us

30

31 of 59

Part 4

Meet Kubernetes

31

32 of 59

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

33 of 59

Nodes

They are servers (virtual machines)

33

34 of 59

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

35 of 59

Pods

They groups of containers that can’t work without each others.

35

36 of 59

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:

  • 1 backend (API)
  • 1 front-end (Website)
  • 1 database (MySQL)

36

37 of 59

Secrets

They are passwords, API keys,...

Anything you would have use a .env file for.

37

38 of 59

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

39 of 59

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

40 of 59

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

41 of 59

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

42 of 59

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

43 of 59

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)

44 of 59

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

45 of 59

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

46 of 59

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

47 of 59

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

48 of 59

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

49 of 59

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

50 of 59

Part 5

Interact with

50

51 of 59

With CLI: Kubectl

51

52 of 59

With UI: Lens

52

53 of 59

Part 6

Let’s deploy!

53

54 of 59

Resources

54

55 of 59

Part 7

Your turn!

55

56 of 59

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:

  • Create a cluster on your laptop for free
  • The basics of deploying & managing an app

57 of 59

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! ;)

58 of 59

Questions

58

59 of 59