Bird
Raised Fist0
Kubernetesdevops~5 mins

Metrics Server installation in Kubernetes - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Sometimes you want to see how much CPU and memory your Kubernetes pods are using. Metrics Server collects this data so you can monitor your cluster's health and make decisions like scaling your apps automatically.
When you want to check resource usage of pods and nodes in your Kubernetes cluster.
When you need to enable Horizontal Pod Autoscaler to scale apps based on CPU or memory.
When you want to troubleshoot performance issues by seeing live metrics.
When you want a simple way to gather cluster metrics without installing heavy monitoring tools.
When you want to use kubectl top commands to see resource usage.
Commands
This command downloads and installs the Metrics Server components into your Kubernetes cluster. It sets up the necessary pods and permissions.
Terminal
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
Expected OutputExpected
namespace/metrics-server created serviceaccount/metrics-server created clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created clusterrole.rbac.authorization.k8s.io/system:metrics-server created clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created deployment.apps/metrics-server created service/metrics-server created apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
This command checks if the Metrics Server pod is running in the kube-system namespace by filtering pods with the label k8s-app=metrics-server.
Terminal
kubectl get pods -n kube-system -l k8s-app=metrics-server
Expected OutputExpected
NAME READY STATUS RESTARTS AGE metrics-server-abcdef1234 1/1 Running 0 30s
-n kube-system - Specifies the namespace where Metrics Server is installed.
-l k8s-app=metrics-server - Filters pods by label to show only Metrics Server pods.
This command shows CPU and memory usage for each node in the cluster, proving that Metrics Server is collecting metrics.
Terminal
kubectl top nodes
Expected OutputExpected
NAME CPU(cores) MEMORY(bytes) worker-node1 120m 500Mi worker-node2 100m 450Mi
This command shows CPU and memory usage for all pods across all namespaces, confirming Metrics Server is working cluster-wide.
Terminal
kubectl top pods --all-namespaces
Expected OutputExpected
NAMESPACE NAME CPU(cores) MEMORY(bytes) default my-app-1234567890-abcde 50m 100Mi kube-system metrics-server-abcdef1234 10m 30Mi
--all-namespaces - Shows metrics for pods in all namespaces.
Key Concept

If you remember nothing else from this pattern, remember: Metrics Server must be installed and running to provide live CPU and memory metrics for your Kubernetes cluster.

Common Mistakes
Not waiting for the Metrics Server pod to be in Running status before using kubectl top commands.
kubectl top commands will fail or show no data if Metrics Server is not ready.
Check pod status with kubectl get pods -n kube-system -l k8s-app=metrics-server and wait until it shows STATUS Running.
Installing Metrics Server without proper permissions or in the wrong namespace.
Metrics Server will not collect metrics if it lacks permissions or is not in kube-system namespace.
Use the official components.yaml from the Metrics Server GitHub release which sets correct permissions and namespace.
Trying to use kubectl top commands before Metrics Server is installed.
kubectl top commands depend on Metrics Server; without it, they will error out.
Always install Metrics Server first before running kubectl top commands.
Summary
Apply the official Metrics Server manifest to install it in your cluster.
Verify the Metrics Server pod is running in the kube-system namespace.
Use kubectl top nodes and kubectl top pods to see live resource usage metrics.

Practice

(1/5)
1. What is the primary purpose of the Kubernetes Metrics Server?
easy
A. To schedule pods on specific nodes
B. To collect live CPU and memory usage data from cluster nodes and pods
C. To store persistent data for applications
D. To manage network policies between pods

Solution

  1. Step 1: Understand Metrics Server role

    The Metrics Server collects resource usage data like CPU and memory from nodes and pods in the cluster.
  2. Step 2: Differentiate from other components

    It does not manage network policies, store data, or schedule pods, which are handled by other Kubernetes components.
  3. Final Answer:

    To collect live CPU and memory usage data from cluster nodes and pods -> Option B
  4. Quick Check:

    Metrics Server = resource usage data collection [OK]
Hint: Metrics Server = live resource data collector [OK]
Common Mistakes:
  • Confusing Metrics Server with network or storage components
  • Thinking it schedules pods
  • Assuming it stores persistent data
2. Which command correctly installs the Metrics Server in a Kubernetes cluster?
easy
A. kubectl run metrics-server --image=metrics-server:latest
B. kubectl create deployment metrics-server
C. kubectl install metrics-server
D. kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

Solution

  1. Step 1: Identify official installation method

    The Metrics Server is installed by applying the official components.yaml manifest from the Kubernetes SIGs GitHub repository using kubectl apply.
  2. Step 2: Check command correctness

    Only kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml uses kubectl apply with the correct URL. Other options use incorrect commands or methods.
  3. Final Answer:

    kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml -> Option D
  4. Quick Check:

    Install Metrics Server = kubectl apply official manifest [OK]
Hint: Use kubectl apply with official components.yaml URL [OK]
Common Mistakes:
  • Using kubectl create or run instead of apply
  • Missing the full URL to the manifest
  • Trying to install with a non-existent command
3. After installing Metrics Server, what is the expected output of kubectl top nodes?
medium
A. A list showing CPU and memory usage for each node
B. An error saying Metrics Server is not found
C. A list of pods running on each node
D. No output, command does nothing

Solution

  1. Step 1: Understand kubectl top nodes command

    This command shows current CPU and memory usage metrics for each node in the cluster, provided Metrics Server is installed and working.
  2. Step 2: Identify expected output

    With Metrics Server installed, it returns a table listing nodes with their CPU and memory usage. Errors or empty output indicate installation or connectivity issues.
  3. Final Answer:

    A list showing CPU and memory usage for each node -> Option A
  4. Quick Check:

    kubectl top nodes = node resource usage list [OK]
Hint: kubectl top nodes shows node CPU/memory usage [OK]
Common Mistakes:
  • Expecting pod lists instead of metrics
  • Assuming command fails after installation
  • Confusing with other kubectl commands
4. You installed Metrics Server but kubectl top pods returns an error. What is the most likely cause?
medium
A. Metrics Server is not running or has permission issues
B. kubectl top pods command is deprecated
C. You need to restart the Kubernetes cluster
D. Pods do not have resource limits set

Solution

  1. Step 1: Analyze error cause

    If kubectl top pods fails, it usually means Metrics Server is not running properly or lacks permissions to gather metrics.
  2. Step 2: Rule out other options

    The command is not deprecated, cluster restart is rarely needed, and missing resource limits does not cause this error.
  3. Final Answer:

    Metrics Server is not running or has permission issues -> Option A
  4. Quick Check:

    kubectl top pods error = Metrics Server problem [OK]
Hint: Check Metrics Server pod status and permissions first [OK]
Common Mistakes:
  • Assuming kubectl top pods is deprecated
  • Restarting cluster unnecessarily
  • Thinking resource limits cause command failure
5. You want to install Metrics Server but your cluster nodes use self-signed certificates causing TLS errors. What is the best way to fix this during installation?
hard
A. Disable TLS on all cluster nodes
B. Install Metrics Server without any changes; it will auto-fix TLS
C. Edit the Metrics Server deployment to add --kubelet-insecure-tls argument
D. Use a different monitoring tool that does not require TLS

Solution

  1. Step 1: Identify TLS issue cause

    Self-signed certificates cause TLS verification errors when Metrics Server connects to kubelets.
  2. Step 2: Apply correct fix

    Adding the --kubelet-insecure-tls flag to Metrics Server deployment disables strict TLS verification, allowing it to work with self-signed certs.
  3. Step 3: Rule out unsafe or incorrect options

    Disabling TLS cluster-wide is unsafe, Metrics Server does not auto-fix TLS, and switching tools is unnecessary.
  4. Final Answer:

    Edit the Metrics Server deployment to add --kubelet-insecure-tls argument -> Option C
  5. Quick Check:

    Self-signed certs fix = add --kubelet-insecure-tls [OK]
Hint: Add --kubelet-insecure-tls flag for self-signed certs [OK]
Common Mistakes:
  • Disabling TLS on nodes (unsafe)
  • Expecting Metrics Server to auto-fix TLS
  • Ignoring TLS errors and proceeding