From 0aa2d04d1ab52406d1a4d2fffca3def75cd3c93f Mon Sep 17 00:00:00 2001 From: Joao P Dubas Date: Wed, 15 May 2024 21:14:32 +0000 Subject: [PATCH] feat(day-02): add instructions for second day Today, we learned: 1. Define multiple containers in a pod 2. Set limits to avoid one service messing up the others 3. Use volumes so the contents of a container are kept between restarts --- README.md | 2 + day-002/README.md | 155 ++++++++++++++++++++++++++++++++++++++++++++++ day-002/pod.yml | 52 ++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 day-002/README.md create mode 100644 day-002/pod.yml diff --git a/README.md b/README.md index 403028f..b489609 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ kubectl 1.29.4 ## Curso por dias * [dia-01][dia-01]: subindo primeiro _cluster_ com [`kind`][kind] e fazendo _deploy_ do primeiro `pod` +* [dia-02][dia-02]: realizando _deploy_ de `pod` com múltiplos _containers_, definição de volume e limitação de recursos Pode ser seguido em no @@ -35,3 +36,4 @@ Pode ser seguido em no [mise-guide]: https://mise.jdx.dev/getting-started.html#quickstart [kind]: https://kind.sigs.k8s.io/ [dia-01]: ./day-001/README.md +[dia-02]: ./day-002/README.md diff --git a/day-002/README.md b/day-002/README.md new file mode 100644 index 0000000..0e89b84 --- /dev/null +++ b/day-002/README.md @@ -0,0 +1,155 @@ +# Descomplicando `Kubernetes` - Dia 02 + +## _Deploy_ do `pod` + +Inicialmente precisamos subir o _cluster_ com [`kind`][kind], seguindo as instruções do [dia-01][dia-01]. + +Com o _cluster_ rodando, podemos fazer o _deploy_ do nosso `pod` usando o comando: + +```bash +kubectl apply -f pod.yml +``` + +Veja os detalhes do `pod` criado usando o comando: + +```bash +kubectl describe pods +``` + +No resultado precisamos garantir que: + +1. Os _containers_ `nginx`, `echo` e `shell` existam +2. Limites de recursos existam +3. O _container_ `nginx` tenha um novo volume no caminho `/opt/nginx` + +
+Esse é um exemplo do resultado gerado + +``` +Name: podsmania +Namespace: default +Priority: 0 +Service Account: default +Node: dk8s-day-001-worker/172.21.0.4 +Start Time: Wed, 15 May 2024 20:46:58 +0000 +Labels: run=podsmania + service=webserver +Annotations: +Status: Running +IP: 10.244.2.7 +IPs: + IP: 10.244.2.7 +Containers: + nginx: + Container ID: containerd://88dc17958d8239662a337239b354d54e93e83e085fec6314509810b83b8ac7f5 + Image: nginx + Image ID: docker.io/library/nginx@sha256:a484819eb60211f5299034ac80f6a681b06f89e65866ce91f356ed7c72af059c + Port: + Host Port: + State: Running + Started: Wed, 15 May 2024 20:47:00 +0000 + Ready: True + Restart Count: 0 + Limits: + cpu: 500m + memory: 128Mi + Requests: + cpu: 300m + memory: 96Mi + Environment: + Mounts: + /opt/nginx from custom-nginx-opt (rw) + /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-6s7g9 (ro) + echo: + Container ID: containerd://6160153c3a075864a8cbbd54a0d9544c87ae1e9b75f2282919422e65f2e7113a + Image: ealen/echo-server + Image ID: docker.io/ealen/echo-server@sha256:ec8a6e95890df937a1eb5fafca033a32172d4f43c1fea1f302931d5f230a137f + Port: + Host Port: + State: Running + Started: Wed, 15 May 2024 20:47:02 +0000 + Ready: True + Restart Count: 0 + Limits: + cpu: 500m + memory: 128Mi + Requests: + cpu: 250m + memory: 96Mi + Environment: + PORT: 3000 + Mounts: + /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-6s7g9 (ro) + shell: + Container ID: containerd://5bccc9905d38438ee05954cdb2e7283dfdb6e1a95ce7c260740887a13ee1ef64 + Image: ubuntu + Image ID: docker.io/library/ubuntu@sha256:3f85b7caad41a95462cf5b787d8a04604c8262cdcdf9a472b8c52ef83375fe15 + Port: + Host Port: + Args: + sleep + infinity + State: Running + Started: Wed, 15 May 2024 20:47:04 +0000 + Ready: True + Restart Count: 0 + Limits: + cpu: 250m + memory: 96Mi + Requests: + cpu: 100m + memory: 32Mi + Environment: + Mounts: + /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-6s7g9 (ro) +Conditions: + Type Status + PodReadyToStartContainers True + Initialized True + Ready True + ContainersReady True + PodScheduled True +Volumes: + custom-nginx-opt: + Type: EmptyDir (a temporary directory that shares a pod's lifetime) + Medium: + SizeLimit: 256Mi + kube-api-access-6s7g9: + Type: Projected (a volume that contains injected data from multiple sources) + TokenExpirationSeconds: 3607 + ConfigMapName: kube-root-ca.crt + ConfigMapOptional: + DownwardAPI: true +QoS Class: Burstable +Node-Selectors: +Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s + node.kubernetes.io/unreachable:NoExecute op=Exists for 300s +Events: + Type Reason Age From Message + ---- ------ ---- ---- ------- + Normal Scheduled 18m default-scheduler Successfully assigned default/podsmania to dk8s-day-001-worker + Normal Pulling 18m kubelet Pulling image "nginx" + Normal Pulled 18m kubelet Successfully pulled image "nginx" in 1.481s (1.481s including waiting) + Normal Created 18m kubelet Created container nginx + Normal Started 18m kubelet Started container nginx + Normal Pulling 18m kubelet Pulling image "ealen/echo-server" + Normal Pulled 18m kubelet Successfully pulled image "ealen/echo-server" in 1.86s (1.86s including waiting) + Normal Created 18m kubelet Created container echo + Normal Started 18m kubelet Started container echo + Normal Pulling 18m kubelet Pulling image "ubuntu" + Normal Pulled 18m kubelet Successfully pulled image "ubuntu" in 1.597s (1.597s including waiting) + Normal Created 18m kubelet Created container shell + Normal Started 18m kubelet Started container shell +``` +
+ +### Limpando o _deploy_ + +Para remover o `pod` criado, executamos o comando: + +```bash +kubectl delete -f pod.yml +``` + +[kind]: https://kind.sigs.k8s.io/ +[dia-01]: ./day-001/README.md diff --git a/day-002/pod.yml b/day-002/pod.yml new file mode 100644 index 0000000..6221191 --- /dev/null +++ b/day-002/pod.yml @@ -0,0 +1,52 @@ +--- +apiVersion: v1 +kind: Pod +metadata: + labels: + run: podsmania + service: webserver + name: podsmania +spec: + containers: + - image: nginx + name: nginx + resources: + limits: + cpu: '0.5' + memory: '128Mi' + requests: + cpu: '0.3' + memory: '96Mi' + volumeMounts: + - mountPath: /opt/nginx + name: custom-nginx-opt + - image: ealen/echo-server + name: echo + resources: + limits: + cpu: '0.5' + memory: '128Mi' + requests: + cpu: '0.25' + memory: '96Mi' + env: + - name: PORT + value: '3000' + - image: ubuntu + name: shell + args: + - sleep + - infinity + resources: + limits: + cpu: '0.25' + memory: '96Mi' + requests: + cpu: '0.1' + memory: '32Mi' + dnsPolicy: ClusterFirst + restartPolicy: Always + volumes: + - name: custom-nginx-opt + emptyDir: + sizeLimit: '256Mi'