2022-09-22 00:43:52 +03:00
|
|
|
$filepath = "logs_$((Get-Date).ToString('MM-dd-yyyy'))"
|
2022-11-04 20:52:48 +03:00
|
|
|
Write-Output "gathering logs and writing to $filepath/"
|
|
|
|
|
|
|
|
kubectl get pod -A -o wide --show-labels > ( New-Item -Path ./$filepath/allpods.out -Force )
|
|
|
|
kubectl get netpol -A -o yaml > ( New-Item -Path ./$filepath/all-netpol-yamls.out -Force )
|
|
|
|
kubectl describe netpol -A > ( New-Item -Path ./$filepath/all-netpol-descriptions.out -Force )
|
|
|
|
|
2022-09-22 00:43:52 +03:00
|
|
|
$npmpod = kubectl get pod -n kube-system -owide --output=custom-columns='Name:.metadata.name,Node:spec.nodeName' | Select-String "npm-win"
|
|
|
|
$rows = @()
|
|
|
|
foreach ($row in (-split $npmpod)) {
|
|
|
|
$rows += $row
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($i = 0; $i -lt $rows.Length; $i += 2) {
|
|
|
|
$npm = $rows[$i]
|
|
|
|
$node = $rows[$i + 1]
|
|
|
|
|
2022-11-04 20:52:48 +03:00
|
|
|
Write-Output "Gathering logs. npm pod: $npm. node: $node"
|
|
|
|
kubectl logs -n kube-system $npm > $filepath/logs_$npm.out
|
2022-09-22 00:43:52 +03:00
|
|
|
|
2022-11-04 20:52:48 +03:00
|
|
|
$ip = kubectl get pod -A -owide --output=custom-columns='IP:.status.podIP,Node:spec.nodeName' | Select-String "$node"
|
2022-09-22 00:43:52 +03:00
|
|
|
$ip = (-split $ip)
|
|
|
|
[string] $ips = ""
|
|
|
|
for ($j = 0; $j -lt $ip.Length; $j += 2) {
|
|
|
|
if($j -ne $ip.Length-2){
|
|
|
|
$ips += $ip[$j] + " "}
|
|
|
|
else{
|
|
|
|
$ips += $ip[$j]
|
|
|
|
}
|
2022-11-04 20:52:48 +03:00
|
|
|
}
|
|
|
|
echo "node $node has IPs: $ips"
|
|
|
|
|
|
|
|
Write-Output "copying ps1 file into $npm"
|
2022-09-22 00:43:52 +03:00
|
|
|
kubectl cp ./pod_exec.ps1 kube-system/"$npm":execw.ps1
|
2022-11-04 20:52:48 +03:00
|
|
|
|
|
|
|
Write-Output echo "executing ps1 file on $npm"
|
2022-09-22 00:43:52 +03:00
|
|
|
kubectl exec -it -n kube-system $npm -- powershell.exe -Command .\execw.ps1 "'$ips'"
|
2022-11-04 20:52:48 +03:00
|
|
|
|
|
|
|
Write-Output "copying logs.zip from $npm"
|
|
|
|
kubectl cp kube-system/"$npm":npm-exec-logs.zip ./$filepath/npm-exec-logs_$node.zip
|
2022-09-22 00:43:52 +03:00
|
|
|
}
|
2022-11-04 20:52:48 +03:00
|
|
|
|
|
|
|
Write-Output "finished capturing all logs. written to $filepath/"
|