Kubernetes resource usage time

5/10/2019

We have a requirement to collect the creation time, modification time and deletion time for all kubernetes objects ( pods, deployment, statefulsets, ingress, services etc)

This is required to calculate the resource usage time for each object. do we have any tools to collect these details. what is the best way to collect the usage details for k8s objects. please let me know

-- P Ekambaram
kubernetes

2 Answers

5/10/2019

Generally it is very strange to calculate usage for Kubernetes objects. These are just objects in Etcd database, they are immaterial.

What you should really do (may be you already do it) is to count usage for compute resources like cpu, memory and storage. For that you may install Prometheus + Grafana. There is very good place to start here: https://github.com/coreos/kube-prometheus. There are a lot of builtin graphs and alerts.

-- Vasily Angapov
Source: StackOverflow

5/11/2019

The information you seek isn't readily available from Kubernetes. You will have to do some coding to achieve your desired goal.

The creation time can be fetched from objects directly using kubectl get <object> -o custom-columns=Name:.metadata.name,StartTime:.metadata.creationTimestamp

To fetch the modification time and deletion time of objects, you can look into the etcd Watch API to monitor for changes to objects inside etcd. As Vasily mentioned, all Kubernetes objects are stored there.

-- Alassane Ndiaye
Source: StackOverflow