diff --git a/11-secrets/01-secrets.yml b/10-secrets/01-secrets.yml similarity index 100% rename from 11-secrets/01-secrets.yml rename to 10-secrets/01-secrets.yml diff --git a/11-secrets/README.md b/10-secrets/README.md similarity index 97% rename from 11-secrets/README.md rename to 10-secrets/README.md index 0b52fac..61bbd05 100644 --- a/11-secrets/README.md +++ b/10-secrets/README.md @@ -18,7 +18,7 @@ data: You can apply the file: ```bash -$ kubectl apply -f 11-secrets/01-secrets. +$ kubectl apply -f 10-secrets/01-secrets.yml secret "mysecret" created ``` diff --git a/12-probes/01-liveness-probe.yml b/11-probes/01-liveness-probe.yml similarity index 100% rename from 12-probes/01-liveness-probe.yml rename to 11-probes/01-liveness-probe.yml diff --git a/12-probes/02-readiness-probe.yml b/11-probes/02-readiness-probe.yml similarity index 100% rename from 12-probes/02-readiness-probe.yml rename to 11-probes/02-readiness-probe.yml diff --git a/12-probes/README.md b/11-probes/README.md similarity index 100% rename from 12-probes/README.md rename to 11-probes/README.md diff --git a/13-resources/README.md b/12-resources/README.md similarity index 100% rename from 13-resources/README.md rename to 12-resources/README.md diff --git a/14-affinity-anti-affinity/01-pod-anti-affinity.yml b/13-affinity-anti-affinity/01-pod-anti-affinity.yml similarity index 100% rename from 14-affinity-anti-affinity/01-pod-anti-affinity.yml rename to 13-affinity-anti-affinity/01-pod-anti-affinity.yml diff --git a/14-affinity-anti-affinity/02-node-affinity.yml b/13-affinity-anti-affinity/02-node-affinity.yml similarity index 100% rename from 14-affinity-anti-affinity/02-node-affinity.yml rename to 13-affinity-anti-affinity/02-node-affinity.yml diff --git a/14-affinity-anti-affinity/README.md b/13-affinity-anti-affinity/README.md similarity index 100% rename from 14-affinity-anti-affinity/README.md rename to 13-affinity-anti-affinity/README.md diff --git a/15-pdb/01-pdb.yml b/14-pdb/01-pdb.yml similarity index 100% rename from 15-pdb/01-pdb.yml rename to 14-pdb/01-pdb.yml diff --git a/15-pdb/README.md b/14-pdb/README.md similarity index 100% rename from 15-pdb/README.md rename to 14-pdb/README.md diff --git a/15-pdb/kind.yml b/14-pdb/kind.yml similarity index 100% rename from 15-pdb/kind.yml rename to 14-pdb/kind.yml diff --git a/16-hpa-vpa/02-hpa.yml b/15-hpa-vpa/02-hpa.yml similarity index 100% rename from 16-hpa-vpa/02-hpa.yml rename to 15-hpa-vpa/02-hpa.yml diff --git a/16-hpa-vpa/README.md b/15-hpa-vpa/README.md similarity index 100% rename from 16-hpa-vpa/README.md rename to 15-hpa-vpa/README.md diff --git a/17-sidecar-containers/README.md b/16-sidecar-containers/README.md similarity index 100% rename from 17-sidecar-containers/README.md rename to 16-sidecar-containers/README.md diff --git a/10-volumes/01-simple-mysql-pv.yml b/17-volumes/01-simple-mysql-pv.yml similarity index 100% rename from 10-volumes/01-simple-mysql-pv.yml rename to 17-volumes/01-simple-mysql-pv.yml diff --git a/10-volumes/02-simple-mysql-pvc.yml b/17-volumes/02-simple-mysql-pvc.yml similarity index 100% rename from 10-volumes/02-simple-mysql-pvc.yml rename to 17-volumes/02-simple-mysql-pvc.yml diff --git a/10-volumes/03-simple-mysql-deployment.yml b/17-volumes/03-simple-mysql-deployment.yml similarity index 100% rename from 10-volumes/03-simple-mysql-deployment.yml rename to 17-volumes/03-simple-mysql-deployment.yml diff --git a/10-volumes/04-simple-mysql-service.yml b/17-volumes/04-simple-mysql-service.yml similarity index 100% rename from 10-volumes/04-simple-mysql-service.yml rename to 17-volumes/04-simple-mysql-service.yml diff --git a/10-volumes/README.md b/17-volumes/README.md similarity index 100% rename from 10-volumes/README.md rename to 17-volumes/README.md diff --git a/18-stateful-set/03-statefulset.yml b/18-stateful-set/03-statefulset.yml new file mode 100644 index 0000000..dd34733 --- /dev/null +++ b/18-stateful-set/03-statefulset.yml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: web +spec: + selector: + matchLabels: + app: nginx # has to match .spec.template.metadata.labels + serviceName: "nginx" + replicas: 3 + template: + metadata: + labels: + app: nginx # has to match .spec.selector.matchLabels + spec: + containers: + - name: nginx + image: k8s.gcr.io/nginx-slim:0.8 + ports: + - containerPort: 80 + name: web + volumeMounts: + - name: www + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: www + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 1Gi \ No newline at end of file diff --git a/18-stateful-set/README.md b/18-stateful-set/README.md new file mode 100644 index 0000000..f017c4b --- /dev/null +++ b/18-stateful-set/README.md @@ -0,0 +1,100 @@ +# Other topics + +## Introduction + +In this section you will get an overview of others k8s useful features, in order of complexity. + +## Namespace + +`Namespaces` is the way to support multiple virtual clusters in k8s. + +They are intended for use in environments with many users spread across multiple teams, or projects. For clusters with a few to tens of users, you should not need to create or think about `namespaces` at all. Start using `namespaces` when you need the features they provide. + +By default, all objects are in the `default` namespace. There is a "hidden" `namespace` where k8s runs services for itself. +Try: + +```bash +$ kubectl get namespace +NAME STATUS AGE +default Active 56d +kube-public Active 56d +kube-system Active 56d +``` + +```bash +$ kubectl get all --namespace=kube-system + +[lot of stuff] +``` + +## `kubeval` + +It is a tool to validate your k8s YAML files: + +The easiest integration is with `docker run`, if you files are in the directory `kubernetes` + +```bash +docker run -it -v `pwd`/kubernetes:/kubernetes garethr/kubeval kubernetes/**/* +``` + +## Helm + +It is a package manager for k8s: . +It contains multiple, ready to use, k8s manifest for projects, for example [mysql](https://github.com/helm/charts/tree/master/stable/mysql) + +## Stateful Set + +Like a `Deployment`, a `StatefulSet` manages Pods that are based on an identical container spec. Unlike a `Deployment`, a `StatefulSet` maintains a sticky identity for each of their Pods. These pods are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling. + +`StatefulSets` are valuable for applications that require one or more of the following. + +* Stable, unique network identifiers, ex: distributed system, like ElasticSearch +* Stable, persistent storage, ex: MySQL +* Ordered, graceful deployment and scaling +* Ordered, automated rolling updates, ex: MySQL Master+Slave + +```yaml +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: web +spec: + selector: + matchLabels: + app: nginx # has to match .spec.template.metadata.labels + serviceName: "nginx" + replicas: 3 # by default is 1 + template: + metadata: + labels: + app: nginx # has to match .spec.selector.matchLabels + spec: + containers: + - name: nginx + image: k8s.gcr.io/nginx-slim:0.8 + ports: + - containerPort: 80 + name: web + volumeMounts: + - name: www + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: www + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 1Gi +``` + +## Exercises + +1. Install `helm`, and use it to install [`redis`](https://github.com/helm/charts/tree/master/stable/redis) in your minikube +2. Configure a stateful set for nginx with a HPA at 1% CPU, in a namespace `staging` + +## Clean up + +```bash +kubectl delete statefulset,deployment,service,pod --all +``` diff --git a/18-controllers/README.md b/19-controllers/README.md similarity index 100% rename from 18-controllers/README.md rename to 19-controllers/README.md diff --git a/19-operators/README.md b/20-operators/README.md similarity index 100% rename from 19-operators/README.md rename to 20-operators/README.md diff --git a/20-rbac/README.md b/21-rbac/README.md similarity index 100% rename from 20-rbac/README.md rename to 21-rbac/README.md diff --git a/21-good-practices/README.md b/99-good-practices/README.md similarity index 100% rename from 21-good-practices/README.md rename to 99-good-practices/README.md diff --git a/21-good-practices/yamllint b/99-good-practices/yamllint similarity index 100% rename from 21-good-practices/yamllint rename to 99-good-practices/yamllint diff --git a/README.md b/README.md index 99ad843..efe6091 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,15 @@ 1. [Deploying my first application: deployment](#deploying-my-first-application-deployment) 1. [Accessing my first application: service](#accessing-my-first-application-service) 1. [Running a background process: cronjob](#running-a-background-process-cronjob) -1. [Running a stateful application: volumes](#running-a-stateful-application-volumes) 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. [HPA, VPA](#hpa-vpa) -1. [Affinity and anti-affinity](#affinity-and-anti-affinity) +1. [Improve the availability of your application: affinity and anti-affinity](#affinity-and-anti-affinity) +1. [Improve the availability of your application: pod disruptions budget](#pdb) +1. [Improve the elasticiy of your applications: HPA, VPA](#hpa-vpa) 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) 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) @@ -200,53 +202,57 @@ See the dedicated [README](08-service). See the dedicated [README](09-cronjob). -## Running a stateful application: `volumes` - -See the dedicated [README](10-volumes). - ## Secrets -See the dedicated [README](11-secrets). +See the dedicated [README](10-secrets). ## Liveness and readiness probes, and how it impacts your pods -See the dedicated [README](12-probes). +See the dedicated [README](11-probes). ## Resources, and how it impacts the scheduling -See the dedicated [README](13-resources). +See the dedicated [README](12-resources). ## Affinity and anti-affinity -See the dedicated [README](14-affinity-anti-affinity). +See the dedicated [README](13-affinity-anti-affinity). ## PDB -See the dedicated [README](15-pdb). +See the dedicated [README](14-pdb). ## HPA, VPA -See the dedicated [README](16-hpa-vpa). +See the dedicated [README](15-hpa-vpa). ## Sidecar containers: what, why, and how -See the dedicated [README](17-sidecar-containers). +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). ## Controllers: what, why, and how -See the dedicated [README](18-controllers). +See the dedicated [README](19-controllers). ## Operators and CRDs: what, why, and how -See the dedicated [README](19-operators). +See the dedicated [README](20-operators). ## RBAC -See the dedicated [README](20-rbac). +See the dedicated [README](21-rbac). ## Good practices -See the dedicated [README](21-good-practices). +See the dedicated [README](99-good-practices). ## Links