Skip to content

Instantly share code, notes, and snippets.

@jellebens
Created June 11, 2024 11:42
Show Gist options
  • Save jellebens/27aac4822a486ef9b4541c1d46320431 to your computer and use it in GitHub Desktop.
Save jellebens/27aac4822a486ef9b4541c1d46320431 to your computer and use it in GitHub Desktop.
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