# kubernetes
in 5 minutes
----
## Kubernetes is a container orchestrator
----
## But it is a kind of magic:
We specify the configuration of applications as our "desired state"
and Kubernetes will try to deploy this configuration. And it will try to maintain it over time whatever happens.

----
## Kubernetes gives us
- Deployment automation
- Fast scalability
- Application upgrades and rollbacks
- Ensure the stability of the applications
- Limit the resources consumed by the applications
- Hot adding and removing resources as nodes
- Automatic provision of disk resources
- Network and security management
- ...
---
## A Kubernetes cluster has 2 kind of nodes:
- Masters
- Workers
----
The core of kubernetes (k8s cluster services) and its API live in each MASTER node
----
We could have a simple master or we could have a bunch of master nodes to ensure the high availability
----
The workers are the container hosts. Composed by:
- A container engine (Most used is docker)
- A service called kubelet to communicate with kubernetes
----

---
## How do we specify what kubernetes has to do?
----
We could define a deployent in a YAML with at least these 3 things:
- Some metadata to describe and classify the deployment
- The image(s) for the container(s) (e.g. an image from the Apache docker)
- And the number of replicas we want (we could choose more than one to have high capacity to answer request and guarantee high availability)
----
Additionally we usually add some of these:
- Live probe tests
- Environment variables
----
Example with 2 applications deployment

----
Each replica is called a POD. A pod contains at least one container. But sometimes it has more, for instance to collect metrics
----
Sometimes we want to keep the state of the container and it's files, for instance for a DB service. Then we will use statefulsets and disk provision
----
In a statefullset we provision some disk space to store the application data.
Kubernetes doesn't care where is it stored, only needs a [plugin called storage class](https://kubernetes.io/docs/concepts/storage/storage-classes/) to manage it. Could be Amazon, Azure or Google block stores, CephFS, cinder, or others.
---
# How does Kubernetes do the job?
Some Examples
----
## A pod failure
The POD (App 1) in the worker 2 has died. Kubernetes is going to create a new pod to mantain the number of replicas

----
## A worker failure
The worker 2 has died, kubernetes will create the PODs in an other worker

----
## Deployment upgrade
We need to update a deployment with a new image.
Kubernetes will stop and re-create one pod every time to ensure that the service doesn't interrupt. If the creation of a POD fails all the process stops to allow investigating the problem without interruption of the service.
----

step 1. Kubernetes creates a new Pod with the new image version
----

step 2 and 3. Kubernetes deletes the replaced pod and creates a new pod.
----

step 4. Kubernetes deletes the last old pod
---
by Ivan Lausuch
SUSE Engineer
{"metaMigratedAt":"2023-06-15T12:30:32.892Z","metaMigratedFrom":"YAML","title":"kubernetes","breaks":true,"slideOptions":"{\"theme\":\"solarized\"}","contributors":"[{\"id\":\"0de751ad-95d4-4fdd-bf2a-c796404864ea\",\"add\":7957,\"del\":4503}]"}