You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kubernetes-hands-on/README.md

296 lines
9.7 KiB
Markdown

5 years ago
# Kubernetes Hands on
1. [Prerequisites](#prerequisites)
1. [What it is not](#what-it-is-not)
1. [What is Kubernetes? What is it used for?](#what-is-kubernetes-what-is-it-used-for)
5 years ago
1. [Glossary](#glossary)
1. [The base building block: pods](#the-base-building-block-pods)
1. [Naming things: labels and annotations](#naming-things-labels-and-annotations)
1. [Deploying your first application: deployment](#deploying-my-first-application-deployment)
1. [Accessing your first application: service](#accessing-my-first-application-service)
1. [Running a background process: cronjobs](#running-a-background-process-cronjobs)
5 years ago
1. [Secrets](#secrets)
1. [Liveness and readiness probes, and how it impacts your pods](#liveness-and-readiness-probes,-and-how-it-impacts-your-pods)
1. [Resources, and how it impacts the scheduling](#resources,-and-how-it-impacts-the-scheduling)
1. [Improving the availability of your application: affinity and anti-affinity](#affinity-and-anti-affinity)
1. [Improving the availability of your application: pod disruptions budget](#pdb)
1. [Improving the elasticity of your applications: HPA, VPA](#hpa-vpa)
5 years ago
1. [Sidecar containers: what, why, and how](#sidecar-containers-what,-why,-and-how)
1. [Running a stateful application: volumes](#running-a-stateful-application-volumes)
1. [Running a stateful application: stateful-sets](#running-a-stateful-application-stateful-sets)
5 years ago
1. [Controllers: what, why, and how](#controllers-what,-why,-and-how)
1. [Operators and CRDs: what, why, and how](#operators-and-crds-what,-why,-and-how)
1. [RBAC](#rbac)
1. [Other topics](#other-topics)
5 years ago
1. [Good practices](#good-practices)
1. [Links](#links)
## License
This hands-on course in under the [CC BY-NC-SA](./LICENSE) license.
5 years ago
![CC BY-NC-SA](https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png)
## Prerequisites
* Homebrew: <https://brew.sh/>
5 years ago
```sh
5 years ago
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```
* Docker: <https://docs.docker.com/docker-for-mac/install/>
5 years ago
```sh
5 years ago
open https://download.docker.com/mac/stable/Docker.dmg
```
* VirtualBox: <https://www.virtualbox.org/wiki/Downloads>
* minikube: <https://github.com/kubernetes/minikube>
Install minikube and the "ingress" and "metrics-server" addons:
5 years ago
```sh
$ brew install kubectl
[...]
$ brew cask install minikube
5 years ago
[...]
$ minikube start
[...]
5 years ago
🏄 Done! Thank you for using minikube!
$ minikube addons enable ingress
✅ ingress was successfully enabled
5 years ago
$ minikube addons enable metrics-server
✅ metrics-server was successfully enabled
$ kubectl config current-context
5 years ago
minikube
```
**Note:** the ingress addon is currently not supported on docker for Mac (see https://github.com/kubernetes/minikube/issues/7332).
As a workaround, you have to deploy minikube as a VM and not as a container (using Virtualbox or Hyperkit for example)
```sh
$ minikube start --vm=true --vm-driver=virtualbox
[...]
✨ Using the virtualbox driver based on user configuration
🔥 Creating virtualbox VM ...
```
If you did launch minikube already, the `--vm` flag may be ignored as minikube caches the previous config. If so you may want to delete and relaunch minikube (warning: it will delete your whole minikube setup)
```sh
$ minikube stop && minikube delete && minikube start --vm=true --vm-driver=virtualbox
[...]
💀 Removed all traces of the "minikube" cluster.
✨ Using the virtualbox driver based on user configuration
🔥 Creating virtualbox VM ...
```
5 years ago
### (Optional) If you feel adventurous, only for macOS
You can try another lighter virtual machine layer than Virtualbox
5 years ago
* HyperKit: <https://github.com/moby/hyperkit>
5 years ago
```sh
5 years ago
brew install docker-machine-driver-hyperkit
```
Then start minikube:
5 years ago
```sh
5 years ago
minikube start --vm-driver=hyperkit
```
If you're encountering any issues:
5 years ago
```sh
5 years ago
rm -rf ~/.minikube/
```
And start minikube without HyperKit:
5 years ago
```sh
5 years ago
minikube start
```
### Completion
If you are using Zsh, you can add the following to your `.zshrc` file to get autocomplete for `kubectl`:
5 years ago
```sh
5 years ago
if [ $commands[kubectl] ]; then
source <(kubectl completion zsh)
fi
```
## What this course is and what it's *not*
5 years ago
### What this is
This is a hands-on course to get started with Kubernetes (Kubernetes). It starts with the basics and moves up in complexity.
At the end of this course, you should be able to deploy an API in Kubernetes that is accessible from the outside.
5 years ago
### What it's *not*
5 years ago
This is not a course on how to install, manage or deploy a Kubernetes cluster.
Neither is it a course to understand how Kubernetes works internally.
However, if you're interested in this topic, see [Kubernetes The Hard Way](https://github.com/kelseyhightower/kubernetes-the-hard-way).
5 years ago
## What is Kubernetes? What is it used for
5 years ago
Kubernetes is an open-source system for managing containerized applications across multiple hosts, providing basic mechanisms for deployment, maintenance, and scaling of applications.
5 years ago
Kubernetes has a number of features. It can be seen as:
5 years ago
* a container platform,
* a microservices platform,
* a portable cloud platform, and a lot more.
5 years ago
Kubernetes provides a container-centric management environment. It orchestrates computing, networking, and storage infrastructure on behalf of user workloads. This provides much of the simplicity of Platform as a Service (PaaS) with the flexibility of Infrastructure as a Service (IaaS), and enables portability across infrastructure providers.
5 years ago
## Glossary
* **YAML (yml)**
5 years ago
A markup language that relies on spaces and tabulations. All Kubernetes configuration is written using YAML.
5 years ago
You will feel the pain of missing tabs and spaces. Feel free to use a linter, such as <http://www.yamllint.com/>.
5 years ago
* **Container**
5 years ago
*Containers* are an abstraction at the app layer, which packages code and dependencies together.
5 years ago
* **(Container) image**
5 years ago
A lightweight, standalone, executable software package that includes everything you need to run an application: code, runtime, system tools, system libraries and settings.
5 years ago
* **Docker**
5 years ago
A software technology providing operating-system-level virtualization, also known as containers.
5 years ago
Docker uses the resource isolation features of the Linux kernel, such as cgroups and kernel namespaces, and a union-capable file system such as OverlayFS and others to allow independent “containers” to run within a single Linux instance. This avoids the overhead of starting and maintaining virtual machines (VMs).
5 years ago
* **kubectl**
The standard CLI to interact with Kubernetes. We use it a lot in this course.
5 years ago
* **minikube**
A local Kubernetes cluster, useful for testing. We use it a lot in this course.
5 years ago
* **Manifest**
5 years ago
Kubernetes configuration files are called *manifests*. This is a reference to the list or invoice of the passengers or goods being carried by a commercial vehicle or ship (from [wiktionary](https://en.wiktionary.org/wiki/manifest#Noun)).
5 years ago
* **(Kubernetes) objects**
5 years ago
Kubernetes contains a number of abstractions that represent the state of your system: deployed containerized applications and workloads, their associated network and disk resources, and other information about what your cluster is doing. These abstractions are called *objects*, and are represented by a *kind* in the Kubernetes API.
* **(Kubernetes) node**
A node is a worker machine in Kubernetes.
A worker machine may be a VM or physical machine, depending on the cluster. It has the necessary services to run the workloads and is managed by the master components. The services on a node include Docker, `kubelet` and `kube-proxy`.
5 years ago
* **(Kubernetes) cluster**
5 years ago
A set of machines, called nodes, that run containerized applications managed by Kubernetes.
5 years ago
A cluster has several worker nodes and at least one master node.
* **(Kubernetes) master**
5 years ago
The *master* is responsible for managing the cluster. It coordinates all activities in your cluster, such as scheduling applications, maintaining applications desired state, scaling applications, and rolling out new updates.
5 years ago
A Kubernetes master automatically handles the scheduling of your services across nodes in the cluster. The masters automatic scheduling takes the available resources of each node into account.
5 years ago
## The base building block: pods
5 years ago
See the dedicated [README](05-pods).
## Naming things: labels and annotations
5 years ago
See the dedicated [README](06-label-annotation).
## Deploying my first application: deployment
5 years ago
See the dedicated [README](07-deployment).
## Accessing my first application: service
5 years ago
See the dedicated [README](08-service).
## Running a background process: cronjobs
5 years ago
See the dedicated [README](09-cronjob).
## Secrets
See the dedicated [README](10-secrets).
5 years ago
## Liveness and readiness probes, and how it impacts your pods
See the dedicated [README](11-probes).
5 years ago
## Resources, and how it impacts the scheduling
See the dedicated [README](12-resources).
5 years ago
## Affinity and anti-affinity
See the dedicated [README](13-affinity-anti-affinity).
5 years ago
## PDB
See the dedicated [README](14-pdb).
5 years ago
## HPA, VPA
See the dedicated [README](15-hpa-vpa).
5 years ago
## Sidecar containers: what, why, and how
See the dedicated [README](16-sidecar-containers).
## Running a stateful application: volumes
See the dedicated [README](17-volumes).
## Running a stateful application: stateful sets
See the dedicated [README](18-stateful-sets).
5 years ago
## Controllers: what, why, and how
See the dedicated [README](19-controllers).
5 years ago
## Operators and CRDs: what, why, and how
See the dedicated [README](20-operators).
5 years ago
## RBAC
See the dedicated [README](21-rbac).
5 years ago
## Other topics
See the dedicated [README](98-other-topics).
5 years ago
## Good practices
See the dedicated [README](99-good-practices).
5 years ago
## Links
* http://kubernetesbyexample.com/
* https://kubernetes.io/docs/home/
* https://kubernetes.io/docs/reference/kubectl/cheatsheet/
* https://hub.docker.com/r/mhausenblas/simpleservice/