Skip to content

Instantly share code, notes, and snippets.

@eosfor
Last active September 3, 2018 15:43
Show Gist options
  • Save eosfor/2e0592d19acceb8b2301d16dc2ffaa4c to your computer and use it in GitHub Desktop.
Save eosfor/2e0592d19acceb8b2301d16dc2ffaa4c to your computer and use it in GitHub Desktop.
Get status of a pod
function Get-PodStatus {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$ContextName,
[Parameter(Mandatory = $false)]
[switch]$All
)
end {
if ($All.IsPresent) {$t = (kubectl get pods -o json --all-namespaces)}
else {$t = (kubectl get pods -o json)}
kubectl config use-context $ContextName > $null
$pods = $t | ConvertFrom-Json
$pods.items | Select-Object @{l = "name"; e = {$_.metadata.name}},
@{l = "namespace"; e = {$_.metadata.namespace}},
@{l = "state"; e = {($_.status.conditions | Sort-Object lastTransitionTime | Select-Object -Last 1).type}},
@{l = "status"; e = {$_.status.phase} },
@{l = "hostIP"; e = {$_.status.hostIP} },
@{l = "podIP"; e = {$_.status.podIP} }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment