Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shriomtri/0f318e34f35f1f19109aae54c1ea9194 to your computer and use it in GitHub Desktop.
Save shriomtri/0f318e34f35f1f19109aae54c1ea9194 to your computer and use it in GitHub Desktop.
Discovering Pod Resource Usage with Kubernetes Metrics

Discovering Pod Resource Usage with Kubernetes Metrics

Introduction

Kubernetes metrics allow you to gain insight into a wide variety of data about your Kubernetes applications. You can use these metrics to gain insight into how your compute resources are being used. In this lab, you will have the opportunity to hone your skills by investigating existing pods running in a Kubernetes cluster to determine which ones are using the most CPU.

Additional Resources

You are working for BeeBox, a company that provides regular shipments of bees to customers. The company is in the process of building a Kubernetes-based infrastructure for some of their software.

It looks like a pod in the cluster may be using more CPU than expected. Search the beebox-mobile namespace for pods with the label app=auth, and determine which of these pods is using the most CPU. Save the name of that pod to a file for future reference.

The cluster does not have Metrics Server installed, so you will need to install it in order to perform this task.

Learning Objectives

  • Install Kubernetes Metrics Server

    Install the Kubernetes Metrics Server in the cluster. Use this file to install Metrics Server: https://raw.githubusercontent.com/ACloudGuru-Resources/content-cka-resources/master/metrics-server-components.yaml

  • Locate the CPU-Using Pod and Write Its Name to a File

    Locate the pod using the most CPU that also meets the following criteria:

    • Located in the beebox-mobile namespace
    • Has the label app=auth

    Ignore any pods that do not meet those criteria, even if they are using more CPU.

    Write the name of the pod to the file /home/cloud_user/cpu-pod-name.txt.

Solution

  1. Log in to the lab server using the credentials provided:

    ssh cloud_user@<PUBLIC_IP_ADDRESS>
    
    

Install Kubernetes Metrics Server

  1. Install Kubernetes Metrics Server:

    kubectl apply -f https://raw.githubusercontent.com/ACloudGuru-Resources/content-cka-resources/master/metrics-server-components.yaml
    
    
  2. Verify Metrics Server is responsive:

    kubectl get --raw /apis/metrics.k8s.io/
    
    
  3. It may take a few minutes for Metrics Server to become responsive to requests.

Locate the CPU-Using Pod and Write Its Name to a File

  1. In the beebox-mobile namespace, determine which pod with the label app=auth is using the most CPU:

    kubectl top pod -n beebox-mobile --sort-by cpu --selector app=auth
    
    
  2. If you get an error message saying metrics are not available, wait a few minutes and then run the command again.

  3. Write the name of the pod to a file:

    echo auth-proc > /home/cloud_user/cpu-pod-name.txt
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment