How kubectl top pod calculates memory
kubectl top pod reports container_memory_working_set_bytes, not the container_memory_usage_bytes metric in Container Service. The two metrics are calculated differently:
container_memory_usage_bytes = container_memory_rss + container_memory_cache + kernel memory
container_memory_working_set_bytes = container_memory_usage_bytes - total_inactive_file (inactive file pages)
container_memory_usage_bytes counts all memory regardless of when it was last accessed. This includes file cache pages that the kernel can reclaim under pressure, which is why it typically reads higher than kubectl top pod.
container_memory_working_set_bytes subtracts inactive file-backed pages -- cold cache that the kernel can free when it needs memory. The result reflects memory the container is actively using.
Why container_memory_working_set_bytes matters
container_memory_working_set_bytes is the actual amount of memory used by the container and is also the basis for restart judgment when a resource limit is configured.