Created
June 11, 2024 11:42
-
-
Save jellebens/27aac4822a486ef9b4541c1d46320431 to your computer and use it in GitHub Desktop.
This file contains 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
param ( | |
[string]$Namespace | |
) | |
if (-not $Namespace) { | |
Write-Host "Usage: .\restart_pods.ps1 -Namespace <namespace>" | |
exit 1 | |
} | |
# Get all pod names in the namespace | |
$pods = kubectl get pods -n $Namespace -o jsonpath="{.items[*].metadata.name}" | |
# Check if any pods were found | |
if (-not $pods) { | |
Write-Host "No pods found in namespace $Namespace" | |
exit 1 | |
} | |
# Convert the pods string to an array | |
$podArray = $pods -split ' ' | |
# Delete each pod | |
foreach ($pod in $podArray) { | |
Write-Host "Deleting pod $pod in namespace $Namespace" | |
kubectl delete pod $pod -n $Namespace | |
} | |
Write-Host "All pods in namespace $Namespace have been restarted." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment