You are on page 1of 6

Lab: Kubernetes Metrics Server

Introduction
Metrics Server is a scalable, efficient source of container resource metrics for Kubernetes built-
in autoscaling pipelines. Metrics Server collects resource metrics from Kubelets and exposes
them in Kubernetes apiserver through Metrics API for use by Horizontal Pod Autoscaler and
Vertical Pod Autoscaler. Metrics API can also be accessed by kubectl top, making it easier to
debug autoscaling pipelines. Metrics Server is not meant for non-autoscaling purposes.

Metrics Server offers:


• A single deployment that works on most clusters
• Scalable support up to 5,000 node clusters
• Resource efficiency: Metrics Server uses 0.5m core of CPU and 4 MB of memory per
node
In this Lab, you will learn below items:
Objectives:

• Installing metrics-server
• Configure metrics-server
• Using metrics-server
Note: Ensure you have running cluster deployed
1. Ensure that you have logged-in as root user with password as linux on kube-master node.

1.1 Let us clone the git repository which contains manifests required for this exercise, by
executing the below command.
# git clone https://github.com/EyesOnCloud/k8s-metrics.git
Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.2 Let us view the manifest metrics-server, by executing the below command.

# cat -n ~/k8s-metrics/metrics-server.yaml

1.3 Let us verify if we are able to view the metrics, by executing the below command.

# kubectl top nodes


Output:

Note: We will not be able to view the metrics as we haven’t installed it yet.

1.4 Let us run the manifest and install the metrics-server, by executing the below command.

# kubectl apply -f ~/k8s-metrics/metrics-server.yaml

Output:

1.5 Let’s verify if the metrics pod is available, by executing the below command.

# kubectl -n kube-system get pods


Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.6 Let us view the metrics now, by executing the below command.

# kubectl top nodes

Output:

Note: Be Patient, it takes 3 to 5 minutes to gather and display the metrics.

1.7 Let us verify metrics of the pods, by executing the below command.

# kubectl -n kube-system top pods


Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.8 Let us sort the pods based on the memory, by executing the below command.
# kubectl -n kube-system top pods --sort-by=memory

Output:

1.9 Let us sort the pods based on the cpu, by executing the below command.
# kubectl -n kube-system top pods --sort-by=cpu

Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.10 Let us view the manifest file to create a simple multi-container pod.

# cat -n ~/k8s-metrics/multi-pod.yaml

Output:

1.11 Let us create the pod, by executing the below command.

# kubectl apply -f ~/k8s-metrics/multi-pod.yaml

Output:

1.12 Let us list the pod, by executing the below command.


# kubectl get pods

Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.13 Let us view the metrics of individual containers of a pod, by executing the below
command.
# kubectl top pod multi-pod --containers

Output:

1.14 Let us cleanup by deleting the pod created.

# kubectl delete -f ~/k8s-metrics/multi-pod.yaml

Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/

You might also like