> For the complete documentation index, see [llms.txt](https://smadi0x86-blog.gitbook.io/smadi0x86-playground/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://smadi0x86-blog.gitbook.io/smadi0x86-playground/certifications/certified-kubernetes-administrator/logging-and-monitoring.md).

# Logging & Monitoring

## Monitor Cluster Components

Metrics server is a monitoring solution for Kubernetes, every Kubernetes cluster can have only one metrics server, it collects metrics from nodes and pods and places them In-memory (not on disk).

Kubelet has a sub-component called cAdvisor and its responsible for retrieving performance metrics from pods and expose them through kubelet API so they can be used by metrics server.

#### You can download metrics server by running:

{% code overflow="wrap" %}

```bash
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
```

{% endcode %}

#### After downloading metrics server, view CPU and Memory consumption of nodes and pods:

```bash
kubectl top node
kubectl top pod
```

### Lab:

No issues identified.

## Managing Application Logs

#### We can create a logging pod using a definition yaml:

<figure><img src="https://4247064012-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFLaJdzZGSq1DpczuSySw%2Fuploads%2FunytvWhu94UkCGfORt02%2Fimage.png?alt=media&amp;token=b65ac6c0-6207-42d6-8918-7c4caf9ac88b" alt=""><figcaption></figcaption></figure>

#### As we create the pod, we can view logs:

```bash
kubectl logs -f event-simulator-pod image-processor # -f for realtime
```

### Lab:

No issues identified.

## Slides

{% file src="/files/iCG9TWfJC70fUc2mMyO6" %}
