# Metrics Server Addon

## Introduction

The Kubernetes cluster Metrics Server addon is an aggregator of resource usage data in your cluster.

## Description

It is an open-source, scalable, and effective cluster addon that provides a means of collecting resource data (like memory and CPU usage) from the kubelet on each worker node. Additionally, it provides data for the Kubernetes Horizontal Pod Autoscaler when used for auto-scaling workloads. Once obtained, that info is exposed inside the Kubernetes API server via the Metrics API. It is an integral part of the core metrics pipeline.

{% hint style="warning" %}
**Warning**

Note: The Metrics Server addon is not meant for non-autoscaling purposes like Grafana or Prometheus monitoring.
{% endhint %}

## Settings

To access and modify the settings, go to the Infrastructure page, check the radio button next to the cluster you wish to modify, then click edit.

<figure><img src="https://584068516-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtZryvDiHvZIhOZofYOWU%2Fuploads%2Fgit-blob-6845c73e4dc06cfac99763a909c7e186ed56245c%2F1639770885.png?alt=media" alt=""><figcaption></figcaption></figure>

Once the new page is open, scroll down the where the cluster addon can be enabled.

<figure><img src="https://584068516-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtZryvDiHvZIhOZofYOWU%2Fuploads%2Fgit-blob-c3943a66db38cfa503a5e396e7d7929936704c18%2F1639770920.png?alt=media" alt=""><figcaption></figcaption></figure>

## CLI

Once installed and activated, the Metrics API can then be accessed using the `kubectl top` command, making for easier debugging of various issues.

### Syntax

{% tabs %}
{% tab title="Bash" %}

```bash
kubectl top [flags] [options]
```

{% endtab %}
{% endtabs %}

### All Available Commands and Flags

{% tabs %}
{% tab title="Bash" %}

```bash
worker1.ubuntu@ip-10-0-1-140:~$ kubectl top
Display Resource (CPU/Memory) usage.

 The top command allows you to see the resource consumption for nodes or pods.

 This command requires Metrics Server to be correctly configured and working on
the server.

Available Commands:
  node        Display Resource (CPU/Memory) usage of nodes
  pod         Display Resource (CPU/Memory) usage of pods

Usage:
  kubectl top [flags] [options]

Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all
commands).
```

{% endtab %}
{% endtabs %}

### Example

{% tabs %}
{% tab title="Bash" %}

```bash
kubectl top pod --namespace web-app


NAME	CPU (CORES)	MEMORY (BYTES)
	nginx-84ac2948db-12bce	14m	1Mi
	nginx-84ac2948db-bc9ae	14m	1Mi
```

{% endtab %}
{% endtabs %}

## YAML Specifications

{% tabs %}
{% tab title="YAML" %}

```yaml
apiVersion: sunpike.platform9.com/v1alpha2
kind: ClusterAddon
metadata:
  labels:
    sunpike.pf9.io/cluster: '<clsuuid>'
    type: metrics-server
  name: <clsuuid>-metrics-server
  namespace: default
spec:
  clusterID: '<clsuuid>'
  override: {}
  type: metrics-server
  version: 0.5.0
  watch: true
```

{% endtab %}
{% endtabs %}

## Conclusion

Addons are updated along with the `pf9-kube` version and can be referenced in the [Support Matrix](https://docs.platform9.com/kubernetes/support-matrix) article. For additional assistance, contact our [support team](https://support.platform9.com/).
