Created
February 9, 2023 18:09
-
-
Save corkupine/aac2d466b96c081207d8e1d6c252a043 to your computer and use it in GitHub Desktop.
Powershell script to restart all deployments and statefulsets in all k8s namespaces
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($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