Skip to content

Instantly share code, notes, and snippets.

@corkupine
Created February 9, 2023 18:09
Show Gist options
  • Save corkupine/aac2d466b96c081207d8e1d6c252a043 to your computer and use it in GitHub Desktop.
Save corkupine/aac2d466b96c081207d8e1d6c252a043 to your computer and use it in GitHub Desktop.
Powershell script to restart all deployments and statefulsets in all k8s namespaces
param($kubecontext)
if ($kubecontext -ne $null){
kubectl config use-context $kubecontext
}
else {
$kubecontext = kubectl config current-context
}
$response = Read-Host "Are you sure you want to restart all pods in $kubecontext ? Type YES to continue"
if ($response -eq "YES"){
(kubectl get namespaces -o json | ConvertFrom-Json).items | ForEach-Object{
kubectl rollout restart statefulset -n $_.metadata.labels.'kubernetes.io/metadata.name'
kubectl rollout restart deployment -n $_.metadata.labels.'kubernetes.io/metadata.name'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment