|
1 |
| -# Other topics |
| 1 | +# Stateful Sets |
2 | 2 |
|
3 | 3 | ## Introduction
|
4 | 4 |
|
5 |
| -In this section you will get an overview of others Kubernetes useful features, in order of complexity. |
6 |
| - |
7 |
| -## Namespace |
8 |
| - |
9 |
| -`Namespaces` is the way to support multiple virtual clusters in Kubernetes. |
10 |
| - |
11 |
| -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. |
12 |
| - |
13 |
| -By default, all objects are in the `default` namespace. There is a "hidden" `namespace` where Kubernetes runs services for itself. |
14 |
| -Try: |
15 |
| - |
16 |
| -```sh |
17 |
| -$ kubectl get namespace |
18 |
| -NAME STATUS AGE |
19 |
| -default Active 56d |
20 |
| -kube-public Active 56d |
21 |
| -kube-system Active 56d |
22 |
| -``` |
23 |
| - |
24 |
| -```sh |
25 |
| -$ kubectl get all --namespace=kube-system |
26 |
| - |
27 |
| -[lot of stuff] |
28 |
| -``` |
29 |
| - |
30 |
| -## `kubeval` |
31 |
| - |
32 |
| -It is a tool to validate your Kubernetes YAML files: <https://github.com/garethr/kubeval> |
33 |
| - |
34 |
| -The easiest integration is with `docker run`, if you files are in the directory `kubernetes` |
35 |
| - |
36 |
| -```sh |
37 |
| -docker run -it -v `pwd`/kubernetes:/kubernetes garethr/kubeval kubernetes/**/* |
38 |
| -``` |
39 |
| - |
40 |
| -## Helm |
41 |
| - |
42 |
| -It is a package manager for Kubernetes: <https://helm.sh/>. |
43 |
| -It contains multiple, ready to use, Kubernetes manifest for projects, for example [mysql](https://github.com/helm/charts/tree/master/stable/mysql) |
44 |
| - |
45 |
| -## Stateful Set |
46 |
| - |
47 |
| -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. |
| 5 | +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 the pods. These are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling. |
48 | 6 |
|
49 | 7 | `StatefulSets` are valuable for applications that require one or more of the following.
|
50 | 8 |
|
@@ -88,10 +46,19 @@ spec:
|
88 | 46 | storage: 1Gi
|
89 | 47 | ```
|
90 | 48 |
|
| 49 | +As you can see the manifest is very close to the one of a deployment. Apply the manigest [01-statefulset.yml](./01-statefulset.yml). |
| 50 | +
|
| 51 | +Look at the pods generated, see how they are generated. Connect to one of the pods: |
| 52 | +
|
| 53 | +```sh |
| 54 | +kubectl exec -ti web-0 /bin/bash |
| 55 | +``` |
| 56 | + |
| 57 | +Write a file in the volume `www`. Terminate the same pod. See what happens. Reconnect to the pod, look at volume `www`. What can you see? |
| 58 | + |
91 | 59 | ## Exercises
|
92 | 60 |
|
93 |
| -1. Install `helm`, and use it to install [`redis`](https://github.com/helm/charts/tree/master/stable/redis) in your minikube |
94 |
| -2. Configure a stateful set for nginx with a HPA at 1% CPU, in a namespace `staging` |
| 61 | +Nothing to see here. |
95 | 62 |
|
96 | 63 | ## Clean up
|
97 | 64 |
|
|
0 commit comments