Monitoring your containers in a pod is key to knowing the utilization and as a measure of auto scaling – HPA / VPA. These metrics will help you set Resource Quotas and Limit Ranges in an OpenShift / OKD / OpenShift cluster. In this guide, I will show you how you can check for Pod / Container metrics from CLI.

OpenShift comes with metrics server installed. For Kubernetes, use our guide below.

How To Deploy Metrics Server to Kubernetes Cluster

As a cluster administrator, you can configure and tune your cluster metrics to the desired state. If metrics are configured correctly, you can use the command below to show for a pod.

$ kubectl describe PodMetrics 

In my project, I have a number of pods as shown below.

$ oc get pods
NAME                                           READY   STATUS    RESTARTS   AGE
harbor-harbor-chartmuseum-5456c9d756-97pdd     1/1     Running   0          38h
harbor-harbor-clair-654dcfd8bf-kgxk4           2/2     Running   0          38h
harbor-harbor-core-76d64c78b6-kv24c            1/1     Running   1          38h
harbor-harbor-database-0                       1/1     Running   0          38h
harbor-harbor-jobservice-849f5cb79-qnw6v       1/1     Running   0          38h
harbor-harbor-notary-server-54cbdcffb7-98qjb   1/1     Running   1          38h
harbor-harbor-notary-signer-5dd4d88c8d-mnq44   1/1     Running   2          38h
harbor-harbor-portal-5cbc6d5897-gnfnz          1/1     Running   0          38h
harbor-harbor-redis-0                          1/1     Running   0          38h
harbor-harbor-registry-5b5767dcb9-btlk7        2/2     Running   0          38h
jaeger-operator-7dbfd8c587-9l9hr               1/1     Running   0          6d15h

We can then check the metrics of harbor-harbor-database-0 pod using the command:

$ oc describe PodMetrics harbor-harbor-database-0

If metrics are configured, the output appears similar to the following, with Cpu and Memory displayed under Usage.

Name:         harbor-harbor-database-0
Namespace:    harbor
Labels:       
Annotations:  
API Version:  metrics.k8s.io/v1beta1
Containers:
  Name:  remove-lost-found
  Usage:
    Memory:  0
  Name:      database
  Usage:
    Cpu:     6m
    Memory:  344348Ki
  Name:      change-permission-of-directory
  Usage:
    Memory:  0
Kind:        PodMetrics
Metadata:
  Creation Timestamp:  2020-04-09T10:32:04Z
  Self Link:           /apis/metrics.k8s.io/v1beta1/namespaces/harbor/pods/harbor-harbor-database-0
Timestamp:             2020-04-09T10:32:04Z
Window:                5m0s
Events:                

For Kubernetes, use the kubectl command and specify namespace at the end using the -n option.

$ kubectl describe PodMetrics kuard
Name:         kuard
Namespace:    default
Labels:       
Annotations:  
API Version:  metrics.k8s.io/v1beta1
Containers:
  Name:  kuard
  Usage:
    Cpu:     101379n
    Memory:  8960Ki
Kind:        PodMetrics
Metadata:
  Creation Timestamp:  2020-04-09T10:40:24Z
  Self Link:           /apis/metrics.k8s.io/v1beta1/namespaces/default/pods/kuard
Timestamp:             2020-04-09T10:39:34Z
Window:                30s
Events:                

It should work just fine. Below are more articles on OpenShift / Kubernetes environment.

Install Harbor Image Registry on Kubernetes / OpenShift with Helm Chart

Ceph Persistent Storage for Kubernetes with Cephfs

Join new Kubernetes Worker Node to an existing Cluster

How To Schedule Pods on Kubernetes Control plane (Master) Nodes