How to Deploy a Metrics Server in Kubernetes

1 min read 232 words

If you would like to deploy a Metrics Server in Kubernetes , then you first need to create a namespace for it to live it, followed by installing the actual metrics server.

Step 1 – Install the Metrics Server

Using kubectl

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.5.0/components.yaml

Using helm

kubectl create namespace metrics

helm install metrics-server \
    stable/metrics-server \
    --version 2.9.0 \
    --namepsace metrics

Step 2 – Get the Metrics Server Status

If you used kubectl above, then you should be able to run:

kubectl get apiservice v1beta1.metrics.k8s.io -o json | jq '.status'

Otherwise with helm, run:

kubectl describe hpa

Step 3 – Verifying the Metrics Server Setup

If you get the following output, then it just means the server is not ready yet, wait a moment longer:

{
  "conditions": [
    {
      "lastTransitionTime": "2022-04-13T13:26:45Z",
      "message": "endpoints for service/metrics-server in \"kube-system\" have no addresses with port name \"https\"",
      "reason": "MissingEndpoints",
      "status": "False",
      "type": "Available"
    }
  ]
}

When the Metrics Server is ready, you will get a response as follows:

{
  "conditions": [
    {
      "lastTransitionTime": "2022-04-13T13:27:08Z",
      "message": "all checks passed",
      "reason": "Passed",
      "status": "True",
      "type": "Available"
    }
  ]
}

Step 4 – A tip to be alerted when ready

You can always watch the above command instead of running the same command over and over above, while waiting for the server to become available:

watch -n1 "kubectl get apiservice v1beta1.metrics.k8s.io -o json | jq '.status'"
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags