Skip to content

Instantly share code, notes, and snippets.

@MattJeanes
Created December 23, 2022 13:01
Show Gist options
  • Save MattJeanes/056ff88626d6022df2032a94733cf382 to your computer and use it in GitHub Desktop.
Save MattJeanes/056ff88626d6022df2032a94733cf382 to your computer and use it in GitHub Desktop.
Shows all Kubernetes deployments, statefulset and daemonset configured requests/limits for CPU and memory
$ErrorActionPreference = "Stop"
Write-Host "Daemonsets:`n"
$daemonsets = kubectl get daemonsets --all-namespaces --output json | ConvertFrom-Json
$daemonsets.items | Sort-Object { $_.metadata.name } | ForEach-Object {
$daemonset = $_
$daemonset.spec.template.spec.containers | Sort-Object Name | ForEach-Object {
Write-Host "$($daemonset.metadata.name) / $($_.Name), memory request: $($_.Resources.Requests.Memory ?? "N/A"), memory limit: $($_.Resources.Limits.Memory ?? "N/A"), cpu request: $($_.Resources.Requests.CPU ?? "N/A"), cpu limit: $($_.Resources.Limits.CPU ?? "N/A")"
}
}
Write-Host "`n`nStatefulsets:`n"
$statefulsets = kubectl get statefulsets --all-namespaces --output json | ConvertFrom-Json
$statefulsets.items | Sort-Object { $_.metadata.name } | ForEach-Object {
$statefulset = $_
$statefulset.spec.template.spec.containers | Sort-Object Name | ForEach-Object {
Write-Host "$($statefulset.metadata.name) / $($_.Name), memory request: $($_.Resources.Requests.Memory ?? "N/A"), memory limit: $($_.Resources.Limits.Memory ?? "N/A"), cpu request: $($_.Resources.Requests.CPU ?? "N/A"), cpu limit: $($_.Resources.Limits.CPU ?? "N/A")"
}
}
Write-Host "`n`nDeployments:`n"
$deployments = kubectl get deployments --all-namespaces --output json | ConvertFrom-Json
$deployments.items | Sort-Object { $_.metadata.name } | ForEach-Object {
$deployment = $_
$deployment.spec.template.spec.containers | Sort-Object Name | ForEach-Object {
Write-Host "$($deployment.metadata.name) / $($_.Name), memory request: $($_.Resources.Requests.Memory ?? "N/A"), memory limit: $($_.Resources.Limits.Memory ?? "N/A"), cpu request: $($_.Resources.Requests.CPU ?? "N/A"), cpu limit: $($_.Resources.Limits.CPU ?? "N/A")"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment