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.

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 <pod-name>

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

$ kubectl 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-database-0
Namespace:    harbor
Labels:       app=harbor
              chart=harbor
              component=database
              controller-revision-hash=harbor-database-d96cf6745
              heritage=Helm
              release=harbor
              statefulset.kubernetes.io/pod-name=harbor-database-0
Annotations:  <none>
API Version:  metrics.k8s.io/v1beta1
Containers:
  Name:  database
  Usage:
    Cpu:     2m
    Memory:  78252Ki
Kind:        PodMetrics
Metadata:
  Creation Timestamp:  2023-08-21T10:51:14Z
Timestamp:             2023-08-21T10:51:14Z
Window:                5m0s
Events:                <none>

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:       <none>
Annotations:  <none>
API Version:  metrics.k8s.io/v1beta1
Containers:
  Name:  kuard
  Usage:
    Cpu:     101379n
    Memory:  8960Ki
Kind:        PodMetrics
Metadata:
  Creation Timestamp:  2022-04-09T10:40:24Z
  Self Link:           /apis/metrics.k8s.io/v1beta1/namespaces/default/pods/kuard
Timestamp:             2023-04-09T10:39:34Z
Window:                30s
Events:                <none>

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here