---
title: Metrics Server (in vCluster)
sidebar_label: Metrics Server in vCluster
---

### Installing metrics server (inside vCluster)

In case the above recommended method of getting metrics in vCluster using the metrics server proxy does not fulfill your requirements and you need a dedicated metrics server installation in the vCluster you can follow this section.
Make sure the vCluster has access to the host clusters nodes. [Enabling real nodes synchronization](../../architecture/nodes.mdx) will create the required RBAC permissions. 

Install the [metrics server](https://github.com/kubernetes-sigs/metrics-server#installation) via the official method into the vCluster.

Wait until the metrics server has started. You should be now able to use `kubectl top pods` and `kubectl top nodes` within the vCluster:
```
kubectl top pods --all-namespaces
NAMESPACE     NAME                              CPU(cores)   MEMORY(bytes)   
kube-system   coredns-854c77959c-q5878          3m           17Mi            
kube-system   metrics-server-5fbdc54f8c-fgrqk   0m           6Mi
```

If you see the below error after installing metrics-server (check [k3s#5334](https://github.com/k3s-io/k3s/issues/5344) for more information):

```
loading OpenAPI spec for "v1beta1.metrics.k8s.io" failed with: failed to retrieve openAPI spec, http error: ResponseCode: 503
```
Create a file named `metrics_patch.yaml` with the following contents:
```
spec:
  template:
    spec:
      containers:
        - name: metrics-server
          command:
            - /metrics-server
            - --metric-resolution=30s
            - --kubelet-insecure-tls=true
            - --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP
```
and apply the patch with kubectl:
```
kubectl patch deployment metrics-server --patch-file metrics_patch.yaml -n kube-system
```

### How does it work?

By default, vCluster will create a service for each node that redirects incoming traffic from within the vCluster to the node kubelet to vCluster itself. This means that if workloads within the vCluster try to scrape node metrics the traffic reaches vCluster first. Vcluster will redirect the incoming request to the host cluster, rewrite the response (pod names, pod namespaces etc) and return it to the requester.
