{"id":16789,"date":"2023-05-22T15:10:19","date_gmt":"2023-05-22T12:10:19","guid":{"rendered":"https:\/\/kifarunix.com\/?p=16789"},"modified":"2024-06-06T07:27:12","modified_gmt":"2024-06-06T04:27:12","slug":"install-kubernetes-metrics-server-on-a-kubernetes-cluster","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-kubernetes-metrics-server-on-a-kubernetes-cluster\/","title":{"rendered":"Install Kubernetes Metrics Server on a Kubernetes Cluster"},"content":{"rendered":"\n<p>This tutorial provides a step-by-step guide on how to install Kubernetes Metrics server on a Kubernetes cluster. <a href=\"https:\/\/github.com\/kubernetes-sigs\/metrics-server\" target=\"_blank\" rel=\"noreferrer noopener\">Kubernetes Metrics Server<\/a> plays a vital role in monitoring your Kubernetes cluster by collecting resource utilization data, such as CPU and memory usage, from various components. It provides valuable insights into the health and performance of your applications, nodes, and pods, enabling you to scale resources efficiently, identify bottlenecks, and troubleshoot issues promptly.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#step-by-step-guide-installing-metrics-server-on-kubernetes-cluster\">Step-by-Step Guide: Installing Metrics Server on Kubernetes Cluster<\/a><ul><li><a href=\"#what-is-the-use-of-kubernetes-metrics-server\">What is the use of Kubernetes Metrics Server?<\/a><\/li><li><a href=\"#installing-kubernetes-metrics-server-on-a-kubernetes-cluster\">Installing Kubernetes Metrics Server on a Kubernetes Cluster<\/a><ul><li><a href=\"#install-and-setup-kubernetes-cluster\">Install and Setup Kubernetes Cluster<\/a><\/li><li><a href=\"#download-metrics-server-manifests\">Download Metrics Server Manifests<\/a><\/li><li><a href=\"#install-kubernetes-metrics-server\">Install Kubernetes Metrics Server<\/a><\/li><\/ul><\/li><li><a href=\"#verify-kubernetes-metrics-server-installation\">Verify Kubernetes Metrics Server Installation<\/a><\/li><li><a href=\"#check-kubernetes-pods-nodes-cpu-and-memory-usage\">Check Kubernetes Pods\/Nodes CPU and Memory Usage<\/a><\/li><li><a href=\"#view-metrics-on-kubernetes-dashboard\">View Metrics on Kubernetes Dashboard<\/a><\/li><\/ul><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-by-step-guide-installing-metrics-server-on-kubernetes-cluster\">Step-by-Step Guide: Installing Metrics Server on Kubernetes Cluster<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-the-use-of-kubernetes-metrics-server\">What is the use of Kubernetes Metrics Server?<\/h3>\n\n\n\n<p>Kubernetes Metrics server can be used in Kubernetes cluster for;<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><code>Horizontal Scaling<\/code><\/strong>: This is also known as <strong><code>scaling out<\/code><\/strong> and it involves increasing or decreasing the number of replicas (instances) of an application or service based on CPU or memory usage. With horizontal scaling, additional pods (containers) are added or removed dynamically to distribute the workload across multiple instances. This approach allows for better utilization of resources and improved application performance as the load is distributed evenly. Mostly used for stateless applications that can scaled without impacting data consistency.<\/li>\n\n\n\n<li><strong><code>Vertical Scaling<\/code><\/strong>: This is also known as <strong><code>scaling up or down<\/code><\/strong> and it involves adjusting the resources (CPU, memory) allocated to individual instances of an application or service. With vertical scaling, you increase or decrease the capacity of each instance by modifying its resource limits. Mostly used for stateful applications that can maintain their own state or data. Vertical scaling has limits dictated by the capacity of the underlying infrastructure.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"installing-kubernetes-metrics-server-on-a-kubernetes-cluster\">Installing Kubernetes Metrics Server on a Kubernetes Cluster<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-and-setup-kubernetes-cluster\">Install and Setup Kubernetes Cluster<\/h4>\n\n\n\n<p>Before you can proceed, we assume that you already have a K8s cluster up and running.<\/p>\n\n\n\n<p>You can check our previous guide on how to install and setup a Kubernetes cluster;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/?s=setup+Kubernetes+Cluster\" target=\"_blank\" rel=\"noreferrer noopener\">Setup Kubernetes Cluster<\/a><\/p>\n\n\n\n<p>Check other <a href=\"https:\/\/github.com\/kubernetes-sigs\/metrics-server#requirements\" target=\"_blank\" rel=\"noreferrer noopener\">requirements<\/a>.<\/p>\n\n\n\n<p>There are two ways in which you can install Metrics server;<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>via the Metric server <strong><code>components manifest file<\/code><\/strong> available on the Github repository<\/li>\n\n\n\n<li>Via the official <strong><code>Helm Chart repository<\/code><\/strong>.<\/li>\n<\/ol>\n\n\n\n<p>In this tutorial, we will use the components manifests file to install Metrics server.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"download-metrics-server-manifests\">Download Metrics Server Manifests<\/h4>\n\n\n\n<p>If you want to update the manifest configurations like resource limits,or other parameters based on your requirements, it is best to download it to your control plane for editing.<\/p>\n\n\n\n<p>Thus, you can download the latest Metrics server components manifest file using the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/github.com\/kubernetes-sigs\/metrics-server\/releases\/latest\/download\/components.yaml<\/code><\/pre>\n\n\n\n<p>This is how default Metrics server components manifest file looks like;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat components.yaml<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>apiVersion: v1\nkind: ServiceAccount\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server\n  namespace: kube-system\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n  labels:\n    k8s-app: metrics-server\n    rbac.authorization.k8s.io\/aggregate-to-admin: \"true\"\n    rbac.authorization.k8s.io\/aggregate-to-edit: \"true\"\n    rbac.authorization.k8s.io\/aggregate-to-view: \"true\"\n  name: system:aggregated-metrics-reader\nrules:\n- apiGroups:\n  - metrics.k8s.io\n  resources:\n  - pods\n  - nodes\n  verbs:\n  - get\n  - list\n  - watch\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: system:metrics-server\nrules:\n- apiGroups:\n  - \"\"\n  resources:\n  - nodes\/metrics\n  verbs:\n  - get\n- apiGroups:\n  - \"\"\n  resources:\n  - pods\n  - nodes\n  verbs:\n  - get\n  - list\n  - watch\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: RoleBinding\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server-auth-reader\n  namespace: kube-system\nroleRef:\n  apiGroup: rbac.authorization.k8s.io\n  kind: Role\n  name: extension-apiserver-authentication-reader\nsubjects:\n- kind: ServiceAccount\n  name: metrics-server\n  namespace: kube-system\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRoleBinding\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server:system:auth-delegator\nroleRef:\n  apiGroup: rbac.authorization.k8s.io\n  kind: ClusterRole\n  name: system:auth-delegator\nsubjects:\n- kind: ServiceAccount\n  name: metrics-server\n  namespace: kube-system\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRoleBinding\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: system:metrics-server\nroleRef:\n  apiGroup: rbac.authorization.k8s.io\n  kind: ClusterRole\n  name: system:metrics-server\nsubjects:\n- kind: ServiceAccount\n  name: metrics-server\n  namespace: kube-system\n---\napiVersion: v1\nkind: Service\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server\n  namespace: kube-system\nspec:\n  ports:\n  - name: https\n    port: 443\n    protocol: TCP\n    targetPort: https\n  selector:\n    k8s-app: metrics-server\n---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server\n  namespace: kube-system\nspec:\n  selector:\n    matchLabels:\n      k8s-app: metrics-server\n  strategy:\n    rollingUpdate:\n      maxUnavailable: 0\n  template:\n    metadata:\n      labels:\n        k8s-app: metrics-server\n    spec:\n      containers:\n      - args:\n        - --cert-dir=\/tmp\n        - --secure-port=4443\n        - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname\n        - --kubelet-use-node-status-port\n        - --metric-resolution=15s\n        image: registry.k8s.io\/metrics-server\/metrics-server:v0.6.3\n        imagePullPolicy: IfNotPresent\n        livenessProbe:\n          failureThreshold: 3\n          httpGet:\n            path: \/livez\n            port: https\n            scheme: HTTPS\n          periodSeconds: 10\n        name: metrics-server\n        ports:\n        - containerPort: 4443\n          name: https\n          protocol: TCP\n        readinessProbe:\n          failureThreshold: 3\n          httpGet:\n            path: \/readyz\n            port: https\n            scheme: HTTPS\n          initialDelaySeconds: 20\n          periodSeconds: 10\n        resources:\n          requests:\n            cpu: 100m\n            memory: 200Mi\n        securityContext:\n          allowPrivilegeEscalation: false\n          readOnlyRootFilesystem: true\n          runAsNonRoot: true\n          runAsUser: 1000\n        volumeMounts:\n        - mountPath: \/tmp\n          name: tmp-dir\n      nodeSelector:\n        kubernetes.io\/os: linux\n      priorityClassName: system-cluster-critical\n      serviceAccountName: metrics-server\n      volumes:\n      - emptyDir: {}\n        name: tmp-dir\n---\napiVersion: apiregistration.k8s.io\/v1\nkind: APIService\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: v1beta1.metrics.k8s.io\nspec:\n  group: metrics.k8s.io\n  groupPriorityMinimum: 100\n  insecureSkipTLSVerify: true\n  service:\n    name: metrics-server\n    namespace: kube-system\n  version: v1beta1\n  versionPriority: 100\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-kubernetes-metrics-server\">Install Kubernetes Metrics Server<\/h4>\n\n\n\n<p>One thing to note before you can proceed, is that Metrics server will be communicating with the following components in the cluster;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>Control Plane API server<\/code><\/strong>: This is the primary way to interact with a Kubernetes cluster and the metrics that are gathered from the cluster components by Metrics server are exposed through this API for consumption by tools like Kubernetes Dashboard.<\/li>\n\n\n\n<li><strong><code>Kubelet<\/code><\/strong>: Kubelet is an agent that runs on each worker node in the cluster. It exposes an API endpoint through which Metrics server will scrape the Pods\/containers resource usage metrics.<\/li>\n<\/ul>\n\n\n\n<p>Metrics server is configured to communicate with these endpoints using TLS certificate that should be signed by cluster CA. Thus, for demo purposes you can disable the SSL\/TLS verification between the Metrics server and the above endpoints using the option, <strong><code>--kubelet-insecure-tls<\/code><\/strong>.<\/p>\n\n\n\n<p>Also, the default components manifest file defines the container port as 10250\/tcp. This port is already used by <strong>kubelet<\/strong> on the cluster;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ss -atlnp | grep 10250<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>LISTEN 0      4096                *:10250            *:*    users:((\"kubelet\",pid=1185141,fd=20))<\/code><\/pre>\n\n\n\n<p>Hence, let&#8217;s change this to a free port, for example, <strong>4443<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim components.yaml<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\n    spec:\n      containers:\n      - args:\n        - --cert-dir=\/tmp\n<strong>        - --secure-port=4443<\/strong>\n        - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname\n        - --kubelet-use-node-status-port\n        - --metric-resolution=15s\n       <strong> - --kubelet-insecure-tls<\/strong>\n...\n        name: metrics-server\n        ports:\n<strong>        - containerPort: 4443<\/strong>\n          name: https\n          protocol: TCP\n<\/code><\/pre>\n\n\n\n<p>Also, to avoid a situation whereby the availability status of Metric-server becomes <strong>False<\/strong> with &#8220;<strong>FailedDiscoveryCheck<\/strong>&#8220;, you need to configure the Pods created by the Metric server Deployment to use the host&#8217;s network namespace (<strong>hostNetwork: true<\/strong>). The Metrics server API service doesn&#8217;t run directly within the virtual cluster network (the overlay network used by Pods for communication), hence the use of this host network.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\n    spec:\n      <strong>hostNetwork: true<\/strong>\n      containers:\n      - args:\n        - --cert-dir=\/tmp\n<strong>        - --secure-port=4443<\/strong>\n        - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname\n        - --kubelet-use-node-status-port\n        - --metric-resolution=15s\n       <strong> - --kubelet-insecure-tls<\/strong>\n...\n        name: metrics-server\n        ports:\n<strong>        - containerPort: 4443<\/strong>\n          name: https\n          protocol: TCP\n<\/code><\/pre>\n\n\n\n<p>Similarly, to solve this &#8220;<strong>panic: unable to load configmap based request-header-client-ca-file: Get &#8220;&#8230;&#8221;: dial tcp &#8230; i\/o timeout<\/strong>&#8220;, you need to update the roles to allow access to <strong>configmaps<\/strong> resources.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>...\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n  labels:\n    k8s-app: metrics-server\n    rbac.authorization.k8s.io\/aggregate-to-admin: \"true\"\n    rbac.authorization.k8s.io\/aggregate-to-edit: \"true\"\n    rbac.authorization.k8s.io\/aggregate-to-view: \"true\"\n  name: system:aggregated-metrics-reader\nrules:\n- apiGroups:\n  - metrics.k8s.io\n  resources:\n  - pods\n  - nodes\n  <strong>- configmaps<\/strong>\n  verbs:\n  - get\n  - list\n  - watch\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: system:metrics-server\nrules:\n- apiGroups:\n  - \"\"\n  resources:\n  - nodes\/metrics\n  verbs:\n  - get\n- apiGroups:\n  - \"\"\n  resources:\n  - pods\n  - nodes\n  <strong>- configmaps<\/strong>\n  verbs:\n  - get\n  - list\n  - watch\n\n<\/code><\/pre>\n\n\n\n<p>In general, this is how our updated configuration is like.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>apiVersion: v1\nkind: ServiceAccount\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server\n  namespace: kube-system\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n  labels:\n    k8s-app: metrics-server\n    rbac.authorization.k8s.io\/aggregate-to-admin: \"true\"\n    rbac.authorization.k8s.io\/aggregate-to-edit: \"true\"\n    rbac.authorization.k8s.io\/aggregate-to-view: \"true\"\n  name: system:aggregated-metrics-reader\nrules:\n- apiGroups:\n  - metrics.k8s.io\n  resources:\n  - pods\n  - nodes\n  - configmaps\n  verbs:\n  - get\n  - list\n  - watch\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: system:metrics-server\nrules:\n- apiGroups:\n  - \"\"\n  resources:\n  - nodes\/metrics\n  verbs:\n  - get\n- apiGroups:\n  - \"\"\n  resources:\n  - pods\n  - nodes\n  - configmaps\n  verbs:\n  - get\n  - list\n  - watch\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: RoleBinding\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server-auth-reader\n  namespace: kube-system\nroleRef:\n  apiGroup: rbac.authorization.k8s.io\n  kind: Role\n  name: extension-apiserver-authentication-reader\nsubjects:\n- kind: ServiceAccount\n  name: metrics-server\n  namespace: kube-system\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRoleBinding\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server:system:auth-delegator\nroleRef:\n  apiGroup: rbac.authorization.k8s.io\n  kind: ClusterRole\n  name: system:auth-delegator\nsubjects:\n- kind: ServiceAccount\n  name: metrics-server\n  namespace: kube-system\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRoleBinding\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: system:metrics-server\nroleRef:\n  apiGroup: rbac.authorization.k8s.io\n  kind: ClusterRole\n  name: system:metrics-server\nsubjects:\n- kind: ServiceAccount\n  name: metrics-server\n  namespace: kube-system\n---\napiVersion: v1\nkind: Service\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server\n  namespace: kube-system\nspec:\n  ports:\n  - name: https\n    port: 443\n    protocol: TCP\n    targetPort: https\n  selector:\n    k8s-app: metrics-server\n---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: metrics-server\n  namespace: kube-system\nspec:\n  selector:\n    matchLabels:\n      k8s-app: metrics-server\n  strategy:\n    rollingUpdate:\n      maxUnavailable: 0\n  template:\n    metadata:\n      labels:\n        k8s-app: metrics-server\n    spec:\n      hostNetwork: true\n      containers:\n      - args:\n        - --cert-dir=\/tmp\n        - --secure-port=4443\n        - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname\n        - --kubelet-use-node-status-port\n        - --metric-resolution=15s\n        - --kubelet-insecure-tls\n        image: registry.k8s.io\/metrics-server\/metrics-server:v0.7.1\n        imagePullPolicy: IfNotPresent\n        livenessProbe:\n          failureThreshold: 3\n          httpGet:\n            path: \/livez\n            port: https\n            scheme: HTTPS\n          periodSeconds: 10\n        name: metrics-server\n        ports:\n        - containerPort: 4443\n          name: https\n          protocol: TCP\n        readinessProbe:\n          failureThreshold: 3\n          httpGet:\n            path: \/readyz\n            port: https\n            scheme: HTTPS\n          initialDelaySeconds: 20\n          periodSeconds: 10\n        resources:\n          requests:\n            cpu: 100m\n            memory: 200Mi\n        securityContext:\n          allowPrivilegeEscalation: false\n          capabilities:\n            drop:\n            - ALL\n          readOnlyRootFilesystem: true\n          runAsNonRoot: true\n          runAsUser: 1000\n          seccompProfile:\n            type: RuntimeDefault\n        volumeMounts:\n        - mountPath: \/tmp\n          name: tmp-dir\n      nodeSelector:\n        kubernetes.io\/os: linux\n      priorityClassName: system-cluster-critical\n      serviceAccountName: metrics-server\n      volumes:\n      - emptyDir: {}\n        name: tmp-dir\n---\napiVersion: apiregistration.k8s.io\/v1\nkind: APIService\nmetadata:\n  labels:\n    k8s-app: metrics-server\n  name: v1beta1.metrics.k8s.io\nspec:\n  group: metrics.k8s.io\n  groupPriorityMinimum: 100\n  insecureSkipTLSVerify: true\n  service:\n    name: metrics-server\n    namespace: kube-system\n  version: v1beta1\n  versionPriority: 100\n<\/code><\/pre>\n\n\n\n<p>Open the metrics server port on firewall on all cluster nodes.<\/p>\n\n\n\n<p>If using UFW;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 4443\/tcp<\/code><\/pre>\n\n\n\n<p>If using something else other than ufw, open the port accordingly.<\/p>\n\n\n\n<p>You can now install Metrics server by applying the Metrics server components manifest configuration file using the command below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f components.yaml<\/code><\/pre>\n\n\n\n<p>Similarly, if you want to directly install the Metrics server without modifying the default configs, then you can execute the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f https:\/\/github.com\/kubernetes-sigs\/metrics-server\/releases\/latest\/download\/components.yaml<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"verify-kubernetes-metrics-server-installation\">Verify Kubernetes Metrics Server Installation<\/h3>\n\n\n\n<p>You can now verify the installation of Metric server on Kubernetes.<\/p>\n\n\n\n<p>Based on the components manifest configuration above, a deployment called <strong><code>metrics-server<\/code><\/strong> will be created under the <strong><code>kube-system<\/code><\/strong> namespace.<\/p>\n\n\n\n<p>To get the details of the Metrics server deployment, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get deployment metrics-server -n kube-system<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre><code>\nNAME             READY   UP-TO-DATE   AVAILABLE   AGE\nmetrics-server   1\/1     1            1           8m16s\n<\/code><\/pre>\n\n\n\n<p>A Pod is also created;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pods -n kube-system<\/code><\/pre>\n\n\n\n<pre><code>\nNAME                              READY   STATUS    RESTARTS      AGE\n...\nmetrics-server-7b4c4d4bfd-rdz8t   1\/1     Running   0             9m21s\n<\/code><\/pre>\n\n\n\n<p>Check API Services;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get apiservices<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>...\nv1beta1.metrics.k8s.io                 kube-system\/metrics-server   True        11m\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"check-kubernetes-pods-nodes-cpu-and-memory-usage\">Check Kubernetes Pods\/Nodes CPU and Memory Usage<\/h3>\n\n\n\n<p>After the installation, the Metrics server will now start collecting resource usage information from the cluster.<\/p>\n\n\n\n<p>Let&#8217;s run top command to check CPU and Memory usage of the Pods in the default namespace;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl top pods<\/code><\/pre>\n\n\n\n<pre><code>\nNAME                                      CPU(cores)   MEMORY(bytes)   \nnagios-core-deployment-694b75b55b-845mh   2m           32Mi            \nnagios-core-deployment-694b75b55b-8lflz   2m           32Mi            \nnagios-core-deployment-694b75b55b-hrw4n   3m           31Mi\n<\/code><\/pre>\n\n\n\n<p>Show metrics for all pods in the given namespace;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl top pod --namespace=NAMESPACE<\/code><\/pre>\n\n\n\n<p>Show metrics for a given pod and its containers;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl top pod POD_NAME --containers<\/code><\/pre>\n\n\n\n<p>Check nodes;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl top nodes<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>NAME                   CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   \nmaster.kifarunix.com   449m         22%    1516Mi          39%       \nwk01.kifarunix.com     120m         6%     1022Mi          26%       \nwk02.kifarunix.com     46m          2%     1035Mi          27%       \nwk03.kifarunix.com     76m          3%     812Mi           21%\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"view-metrics-on-kubernetes-dashboard\">View Metrics on Kubernetes Dashboard<\/h3>\n\n\n\n<p>You can install Kubernetes dashboard and used it to view Pods\/containers metrics;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-kubernetes-dashboard-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Easy Way to Install Kubernetes Dashboard on Ubuntu 22.04\/20.04<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1889\" height=\"742\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/kubernetes-pods-metrics-cpu-memory.png\" alt=\"Install Metrics Server on Kubernetes\" class=\"wp-image-16794\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/kubernetes-pods-metrics-cpu-memory.png?v=1684756409 1889w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/kubernetes-pods-metrics-cpu-memory-768x302.png?v=1684756409 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/kubernetes-pods-metrics-cpu-memory-1536x603.png?v=1684756409 1536w\" sizes=\"(max-width: 1889px) 100vw, 1889px\" \/><\/figure>\n\n\n\n<p>Kubernetes Dashboard automatically integrates with the Metrics Server. The Metrics Server provides the necessary resource utilization metrics, such as CPU and memory usage, which the Dashboard utilizes to display information and statistics about your cluster.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h2>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/what-are-the-core-concepts-in-kubernetes\/\" target=\"_blank\" rel=\"noreferrer noopener\">What are the core concepts in Kubernetes?<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/kubernetes-architecture-a-high-level-overview-of-kubernetes-cluster-components\/\" target=\"_blank\" rel=\"noreferrer noopener\">Kubernetes Architecture: A High-level Overview of Kubernetes Cluster Components<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial provides a step-by-step guide on how to install Kubernetes Metrics server on a Kubernetes cluster. Kubernetes Metrics Server plays a vital role in<\/p>\n","protected":false},"author":10,"featured_media":16794,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[1076,1077,121,1668],"tags":[6774,6775,6777,6776],"class_list":["post-16789","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-containers","category-docker","category-howtos","category-kubernetes","tag-install-metrics-server-on-kubernetes","tag-kubernetes-metrics-server","tag-step-by-step-guide-how-to-install-metrics-server-on-kubernetes","tag-view-kubernetes-metrics-on-dashboard","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/16789"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=16789"}],"version-history":[{"count":15,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/16789\/revisions"}],"predecessor-version":[{"id":22688,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/16789\/revisions\/22688"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/16794"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=16789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=16789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=16789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}