Last active
September 3, 2018 15:43
-
-
Save eosfor/2e0592d19acceb8b2301d16dc2ffaa4c to your computer and use it in GitHub Desktop.
Get status of a pod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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