<p>I'm new in Kubernetes and currenlty I'm researching about profiling in Kubernetes. I want to log deployment process in Kubernetes (creating pod, restart pod, etc) and want to know the time and resources(RAM, CPU) needed in each process (for example when downloading image, building deployment, pod, etc).</p>

<p>Is there a way or tool for me to log this process? Thank you!</p>

jsishere
<p>I am not really sure you can achieve the outcome you want without extensive knowledge about certain components and some deep dive coding. </p>

<h2>What can be retrieved from Kubernetes:</h2>

<h3>Information about events</h3>

<p>Like pod creation, termination, allocation with timestamps: </p>

<p><code>$ kubectl get events --all-namespaces</code> </p>

<p>Even in the <code>json</code> format there is nothing about CPU/RAM usage in this events.</p>

<h3>Information about pods</h3>

<p><code>$ kubectl get pods POD_NAME -o json</code></p>

<p>No information about CPU/RAM usage. </p>

<p><code>$ kubectl describe pods POD_NAME</code></p>

<p>No information about CPU/RAM usage either. </p>

<h3>Information about resource usage</h3>

<p>There is some tools to monitor and report basic resource usage:</p>

<p><code>$ kubectl top node</code></p>

<p>With output: </p>

<pre><code>NAME                                             CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
MASTER                                           90m          9%     882Mi           33%
WORKER1                                          47m          5%     841Mi           31%
WORKER2                                          37m          3%     656Mi           24%
</code></pre>

<p><code>$ kubectl top pods --all-namespaces</code></p>

<p>With output: </p>

<pre><code>NAMESPACE       NAME                                                        CPU(cores)   MEMORY(bytes)
default         nginx-local-84ddb99b55-2nzdb                                0m           1Mi
default         nginx-local-84ddb99b55-nxfh5                                0m           1Mi
default         nginx-local-84ddb99b55-xllw2                                0m           1Mi
</code></pre>

<p>There is CPU/RAM usage but in basic form. </p>

<h3>Information about deployments</h3>

<p><code>$ kubectl describe deployment deployment_name</code> </p>

<p>Provided output gives no information about CPU/RAM usage. </p>

<h3>Getting information about resources</h3>

<p>Getting resources like CPU/RAM usage specific to some actions like pulling the image or scaling the deployment could be problematic. Not all processes are managed by Kubernetes and additional tools at OS level might be needed to fetch that information.</p>

<p>For example pulling an image for deployment engages the kubelet agent as well as the <a href="https://kubernetes.io/blog/2016/12/container-runtime-interface-cri-in-kubernetes/" rel="nofollow noreferrer">CRI</a> to talk to Docker or other Container Runtime your cluster is using. Adding to that, the Container Runtime not only downloads the image, it does other actions that are not directly monitored by Kubernetes.</p>

<p>For another example HPA (Horizontal Pod Autoscaler) is Kubernetes abstraction and getting it's metrics would be highly dependent on how the metrics are collected in the cluster in order to determine the best way to fetch them.</p>

<p>I would highly encourage you to share what exactly (case by case) you want to monitor. </p>
