owned this note
owned this note
Published
Linked with GitHub
---
tags: presentation
slideOptions:
theme: darcula
transition: 'fade'
---
# Introduction to Kubernetes (K8s)
---
## Marcin Dąbrowski
---
## What is Kubernetes?
---

---
* An open source container orchestration (automated configuration, coordination and management) platform
* Announced by Google in 2014, version 1.0 released in 2015
* Tool that offers high availability, scalability and self-healing of deployed services (applications)
---
## What is a container?
---

---
* A standalone, independent unit of software that packages up code and its dependencies and allows for an application's usage in different environments (i.e. operating systems)
* An abstraction of the app layer instead of being an abstraction of physical hardware, like VMs are. That allows a container to take up less space than a VM would - no need to have a full copy of an operating system, libraries, executable files etc. Only necessary dependencies are inside a container.
---

---

---
## What is a pod?
---

---
* The smallest, ephemeral execution unit in K8s. It is an abstraction layer over a container(s).
* A pod manages containers running inside of itself
* Pods are created by controllers running inside of a node
---
### Problem:
When a pod dies a new one is created and is given a **new** IP address
---
## What is a service?
---

---
* An abstraction of an application running on a set of pods
* Service's IP address is permanent and that fact assures that communication (e.g. between frontend and backend running on two different sets of pods) won't be lost after a pod dies, is reborn and is given a new IP address. Service keeps track of its set of pods and they are automatically 'attached' to it after replication
* An ingress can be used to allow for a service to be reachable from outside the cluster
---
## What is a (worker) node?
---

---
* A physical or virtual machine that pods and services are being run on
* Is controlled by a control plane (master node).
* Every node runs kubelet process (responsible for making sure that pods are running), kube-proxy, which facilitates Kubernetes networking services, and container (e.g. Docker) runtime process which is responsible for downloading images from repositories and running containers (images) in pods
---
## What is a control plane (master node)?
---

---
* A special node that is responsible for controlling all of the worker nodes inside a cluster
* Usually needs less resources than a worker node
* Incomparably more important, so backups are needed
---
* The main entrypoint to a cluster from the outside
* Runs processes like API server, scheduler, controller-manager, cloud-controller-manager and etcd
---
## What is a cluster?
---

---
* A unit that is created after deploying Kubernetes
* It consits of a master node(s) and workers connected over a virtual, internal network (each cluster should have its own DNS server)
* Cluster is not responsible for managing any data. External volumes can be connected to a cluster (pods/services inside of it) and data can be stored but K8s doesn't take responsibility for managing it.
* Can be controlled using API, CLI or Web UI(Dashboard)
---
## Replication - Deployments and StatefulSet
To provide high availability and scalability of services K8s uses replication of pods. Some pods may be stateless, meaning that they can be replicated without any restrictions and other ones may be stateful (like DBs) and may, for example, use external volumes and thus should be synchronized and ordered. Deployment mechanism should be used for replicating stateless pods and StatefulSet should be used for the latter.
---
## More on deployments
---
### Recreate Deployment
Terminates all currently running pods and recreates them with a new version of software. Mostly used in development environments.
---
### Rolling Update Deployment

---
Replicates old versions of application with a newer versions, but does it over an extended period of time
---
### Blue/green Deployment

---
Offers a rapid transition form old version to new version. New, green, version is deployed along with old, blue, version and when the green one becomes ready for deployment (i.e. is considered stable and tested), a Service object switches versions instantaneously. Requires double the resources.
---
### Canary Deployment

---
A group of users is routed to a new version of application which is being run on a small set of pods, to test the new version in production. When testing is done the new versions are scaled up and old ones are scaled down.
---
## StatefulSets
As mentioned before, some pods may have state e.g. use an external volume to store data. If one wants to scale stateful pods, the ordering and uniqueness of these pods must be preserved. That's what the StatefulSet workload API object is used for.
---
## How to manage a Kubernetes cluster?
The most important tool that lets user control clusters is **kubectl**. It is a command tool that can be run in shell (locally or in the cloud) and allows for:
---
* Viewing and finding resources
* **get**
* Updating resources
* **rollout**
* Patching resources
* **patch**
* Editing resources
* **edit**
* Scaling resources
* **scale**
---
And many more interactions with a Kubernetes cluster:
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
---
### Learning materials:
https://www.qwiklabs.com/quests/116
https://www.qwiklabs.com/focuses/878?parent=catalog
https://www.qwiklabs.com/focuses/639?parent=catalog
https://www.qwiklabs.com/focuses/1205?parent=catalog
---
### Documentation
https://kubernetes.io/docs/concepts/workloads/pods/
https://kubernetes.io/docs/concepts/services-networking/service/
https://kubernetes.io/docs/concepts/architecture/nodes/
https://kubernetes.io/docs/concepts/overview/components/
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/
https://kubernetes.io/docs/reference/kubectl/cheatsheet/