Add sections
This commit is contained in:
parent
3c3865fa9e
commit
c73ed21d30
|
@ -1,11 +1,15 @@
|
|||
# The base building block: `pod`
|
||||
|
||||
## Introduction
|
||||
|
||||
In this section we will learn what is a pod, deploy your first container, configure k8s, and interact with k8s in the command line.
|
||||
|
||||
The base job of k8s is to schedule pods. K8s will choose how and where to schedule them. You can also see a pod as an object that requests some CPU & RAM, and k8s will take those requirements into account in his scheduling.
|
||||
|
||||
But it has a base assumption that a pod can be killed whenever it wants to. So keep in mind that a pod is **mortal** and it **will** be destroyed at some point.
|
||||
|
||||
## First pod
|
||||
|
||||
Let's start to deploy this docker image https://hub.docker.com/r/mhausenblas/simpleservice/.
|
||||
It's a stateless python JSON API that answers on:
|
||||
|
||||
|
@ -47,6 +51,8 @@ pod "simple-service" created
|
|||
|
||||
We also could have used the `kubectl create -f ...`. But it's better to have a declarative approach in k8s rather than an imperative one (see: https://medium.com/bitnami-perspectives/imperative-declarative-and-a-few-kubectl-tricks-9d6deabdde)
|
||||
|
||||
## `kubectl get`
|
||||
|
||||
Now list all the pods running in k8s. `get` is the `ls` of k8s.
|
||||
|
||||
```bash
|
||||
|
@ -56,6 +62,8 @@ NAME READY STATUS RESTARTS AGE
|
|||
simple-service 1/1 Running 0 4s
|
||||
```
|
||||
|
||||
## Logs
|
||||
|
||||
Let's have a look at the logs of this pod:
|
||||
|
||||
```bash
|
||||
|
@ -66,6 +74,8 @@ $ kubectl logs simple-service
|
|||
2018-10-01T09:23:21 INFO 200 GET /info (172.17.0.1) 1.38ms [at line 1946]
|
||||
```
|
||||
|
||||
## `kubectl describe`
|
||||
|
||||
Our first pod is now running. Now `describe` it. `describe` is a `get` in steroid, with more information.
|
||||
|
||||
```bash
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# Naming things: `label` & `annotation`
|
||||
|
||||
## Introduction
|
||||
|
||||
In this section we will learn how to name things in k8s, and how to find them again.
|
||||
|
||||
Labels are the way to organise objects in kubernetes. The labels are a list of key/value.
|
||||
|
@ -12,6 +14,8 @@ Valid label keys have two segments: an optional prefix and name, separated by a
|
|||
|
||||
Valid label values must be 63 characters or less and must be empty or begin and end with an alphanumeric character `[a-z0-9A-Z]` with dashes `-`, underscores `_`, dots `.`, and alphanumerics between.
|
||||
|
||||
## Labels in action
|
||||
|
||||
Apply the pod `05-label-annotation/01-simple-service.yml`. It is the same as `04-pods/01-simple-service.yml` but with 2 labels:
|
||||
* `env`: `production`
|
||||
* `tier`: `backend`
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
# Deploying my first application: `deployment`
|
||||
|
||||
## Introduction
|
||||
|
||||
In this section you will learn how to deploy a stateless application with multiple replicas and scale it.
|
||||
|
||||
Managing pods manually is doable, but what if you want to deploy multiple times the same one?
|
||||
Of course you can copy/paste the yaml files and `apply` them. But remember, pods are **mortal**, so k8s can kill them whenever it feels like it.
|
||||
So you can either have a look for your k8s cluster to recreate pods when needed, or you can use a `deployment`.
|
||||
|
||||
## First deployment
|
||||
|
||||
Let's create our first deployment:
|
||||
|
||||
```yml
|
||||
|
@ -45,6 +49,8 @@ $ kubectl apply -f 06-deployment/01-simple-deployment.yml
|
|||
deployment.apps "simple-deployment" created
|
||||
```
|
||||
|
||||
## Inside a `deployment`
|
||||
|
||||
Let's have a look at what this `deployment` created for us:
|
||||
|
||||
```bash
|
||||
|
@ -89,6 +95,8 @@ We see 3 things, you might have a section `ClusterIP` ignore it for now:
|
|||
So in fact k8s created more `kind` than expected.
|
||||
We won't go into details of what a [`ReplicaSet`](https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/) is, just keep it mind that it ensures that a specified number of pod replicas are running at any one time.
|
||||
|
||||
## Scale up
|
||||
|
||||
Let's play with our deployment now.
|
||||
Update the number of `replicas` in the yaml, to a reasonnable number - say `5`.
|
||||
|
||||
|
@ -106,10 +114,14 @@ You can also edit the configuration in place with `kubectl edit`:
|
|||
$ kubectl edit deployment simple-deployment
|
||||
```
|
||||
|
||||
I would recommend to only use `kubectl apply` as it declarative and your local computer, so you can commit it afterwards.
|
||||
|
||||
What is happening? What changed?
|
||||
You can use the flag `--watch` to `kubectl`, for example: `kubectl get pod --watch`.
|
||||
Do not forget the `kubectl logs [...]` command.
|
||||
|
||||
## Scale down
|
||||
|
||||
Change again the number of replicas to `2`, reapply, see what is happening.
|
||||
|
||||
We know how to scale up/down a deployment, but how can we deploy a new version of the application. To achieve this, we need to tell k8s to update the image we are using in our deployment, for this:
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
# Accessing my first application: `service`
|
||||
|
||||
## Introduction
|
||||
|
||||
In this section you will learn how to access your application from outside your cluster, and do service discovery.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
If it's not already done install the `minikube` addon `coredns` & `ingress`
|
||||
```bash
|
||||
$ minikube addons enable coredns
|
||||
|
@ -11,6 +15,8 @@ $ minikube addons enable ingress
|
|||
ingress was successfully enabled
|
||||
```
|
||||
|
||||
## First `service`
|
||||
|
||||
You are able to deploy an image with multiple replicas, but it is not very convenient to access it. You need to know the IP of a `pod` to be able to target your application. And it's not accessible from the outside of the cluster.
|
||||
|
||||
What we need is a `service`. It'll allow us to acces our pods internally or externally.
|
||||
|
@ -94,6 +100,8 @@ Can you access this service from the outside of k8s?
|
|||
|
||||
The answer is no, it's not possible. To do this you need an `ingress`. Ingress means "entering into".
|
||||
|
||||
## Ingress
|
||||
|
||||
You need to connect internet to the ingress that'll connect it to a service:
|
||||
|
||||
```
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
# Running a background process: `cronjob`
|
||||
|
||||
In this section you will lean how to run background tasks using crons & deployments.
|
||||
## Introduction
|
||||
|
||||
In this section you will lean how to run background tasks using crons & jobs.
|
||||
|
||||
## `CronJob`
|
||||
|
||||
Let's start with crons. Crons are like the cron in linux a time-based job scheduler.
|
||||
|
||||
|
@ -35,6 +39,8 @@ cronjob.batch "simple-cronjob" created
|
|||
|
||||
Wait a bit and access the logs of the pod created by the cron.
|
||||
|
||||
## `Job`
|
||||
|
||||
If you need to run a one time job, you can use the `Job` in kubernetes. In fact the `CronJob` will start a `Job` for you at the scheduled interval.
|
||||
|
||||
```yml
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
# Running a stateful application: `volumes`
|
||||
|
||||
## Introduction
|
||||
|
||||
In this section you will learn how to deploy a stateful application, mysql in this example.
|
||||
|
||||
As you know a `pod` is mortal, meaning it can be destroyed by k8s anytime, and with it it's local data, memory, etc. So it's perfect for stateless applications. Of course, in the real world we need a way to store our data, and we need this data to be persistent in time.
|
||||
|
||||
So how can we deploy a stateful application with a persistent storage in k8s? Let's deploy a mysql.
|
||||
|
||||
## Volumes
|
||||
|
||||
We need to review what a volume is before continuing with the deployment of our mysql. As stated above, the disk of a pod is detroyed with it, so it's lost. For a database it'll nice if we could keep the data between restarts of the pods. Here comes the `volume`.
|
||||
|
||||
We can see a `pod` as something that requests CPU & RAM. We can see a `volume` as something that requests a storage on disk. K8s handles a lot of different kind of volumes - 26 has this file hands on is written - from local disk storage to s3.
|
||||
|
@ -66,6 +70,8 @@ The configuration is pretty similiar to the `PersistentVolume`.
|
|||
$ kubectl apply -f 09-stateful-set/02-simple-mysql-pvc.yml
|
||||
```
|
||||
|
||||
## Stateful application
|
||||
|
||||
Now let's create the `deployment` of mysql:
|
||||
|
||||
```bash
|
||||
|
|
Loading…
Reference in New Issue