Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query to check if Pods have Requests or Limits #86

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Author: Microsoft Azure
// Display name: Detect Pods with missing Requests or Limits
// Description: Detect Pods with missing Requests or Limits.
// Categories: Containers,Azure Resources
// Resource types: Kubernetes services
// Solutions: ContainerInsights
// Topic: Diagnostics

let podCounters = Perf
| where ObjectName == 'K8SContainer' and (CounterName == 'cpuLimitNanoCores' or CounterName == 'cpuRequestNanoCores' or CounterName == 'memoryLimitBytes' or CounterName == 'memoryRequestBytes')
| summarize d = make_bag(pack(CounterName, CounterValue)) by InstanceName
| evaluate bag_unpack(d);
let podRequestsAndLimits = podCounters
| extend InstanceNameParts = split(InstanceName, "/")
| extend PodUI = tostring(InstanceNameParts[(array_length(InstanceNameParts)-2)])
| extend PodName = tostring(InstanceNameParts[(array_length(InstanceNameParts)-1)])
| project PodUI, PodName, cpuLimitNanoCores, cpuRequestNanoCores, memoryLimitBytes, memoryRequestBytes;
let nodeCounters = Perf
| where ObjectName == "K8SNode" and (CounterName == 'cpuAllocatableNanoCores' or CounterName == 'cpuCapacityNanoCores' or CounterName == 'memoryAllocatableBytes' or CounterName == 'memoryCapacityBytes')
| summarize d = make_bag(pack(CounterName, CounterValue)) by InstanceName
| evaluate bag_unpack(d);
let nodeCapacity = nodeCounters
| extend InstanceNameParts = split(InstanceName, "/")
| extend Computer = tostring(InstanceNameParts[(array_length(InstanceNameParts)-1)])
| project-away InstanceNameParts, InstanceName;
KubePodInventory
| distinct ClusterName, Computer, Namespace, ContainerName
| extend InstanceNameParts = split(ContainerName, "/")
| extend PodUI = tostring(InstanceNameParts[(array_length(InstanceNameParts)-2)])
| extend PodName = tostring(InstanceNameParts[(array_length(InstanceNameParts)-1)])
| project ClusterName, Computer, Namespace, PodUI, PodName
| join kind= leftouter (nodeCapacity) on Computer
| join kind= leftouter (podRequestsAndLimits) on PodUI, PodName
// Pods without CPU Requests. If container cpu resource requests are not specified, cpuRequestNanoCores metric will not be collected
| extend CPURequests = isnotnull(cpuRequestNanoCores)
// Pods without CPU Limits. If container resource limits are not specified, node's capacity will be rolled-up as container's limit
| extend CPULimits = cpuAllocatableNanoCores != cpuLimitNanoCores
// Pods without Memory Requests. If container memory resource requests are not specified, memoryRequestBytes metric will not be collected
| extend MemoryRequests = isnotnull(memoryRequestBytes)
// Pods without Memory Limits. If container resource limits are not specified, node's capacity will be rolled-up as container's limit
| extend MemoryLimits = memoryAllocatableBytes != memoryLimitBytes
| distinct ClusterName, Namespace, PodName, CPURequests, CPULimits, MemoryRequests, MemoryLimits
| where not(CPURequests) or not(CPULimits) or not(MemoryRequests) or not(MemoryLimits)
| project ClusterName, Namespace, PodName, CPURequests, CPULimits, MemoryRequests, MemoryLimits