---
slug: "kubernetes-restart-pod-delay"
title: "Easily Rolling Restart Kubernetes Pod (Pod Deletion Command)"
description: "When `kubectl rollout restart` makes Pods take too long to restart, check `terminationGracePeriodSeconds` and any preStop hooks — both are common bottlenecks."
url: "https://www.ytyng.com/en/blog/kubernetes-restart-pod-delay"
publish_date: "2021-12-11T13:28:40Z"
created: "2021-12-11T13:28:40Z"
updated: "2026-05-11T13:21:29.555Z"
categories: ["kubernetes"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/933e18bc4f3b4d04836bd65b1eb16abd.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# Easily Rolling Restart Kubernetes Pod (Pod Deletion Command)

<p>In Kubernetes, within a Pod's Deployment, the container configuration looks like this:</p>
<pre><span>apiVersion</span>: apps/v1<br /><span>kind</span>: Deployment<br />metadata:<br />  name: myapp-deployment<br />  namespace: mynamespace<br /><span>spec</span>:<br />  replicas: 2<br />  <span>selector</span>:<br />    <span>matchLabels</span>:<br />      <span>app</span>: myapp<br />  <span>template</span>:<br />    <span>metadata</span>:<br />      <span>labels</span>:<br />        <span>app</span>: myapp<br />    <span>spec</span>:<br />      <span>containers</span>:<br />        - <span>name</span>: myapp<br />          <span>image</span>: myrepo/myapp:<strong>latest</strong><br />          <strong>imagePullPolicy: Always</strong></pre>
<p>If you are operating with the container tag set to latest and imagePullPolicy: Always.</p>
<p>In this case, to reflect the latest code, you would use <code>kubectl delete pod</code>, but by deleting the pods at staggered intervals, you can avoid downtime.</p>
<p>While <code>kubectl delete pod</code> itself waits for the deletion and restart of the pod, if there is downtime until the application starts up after the pod restarts, this can be avoided.</p>
<p>A common approach is using this script:</p>
<p></p>
<h4>restart-pod.sh</h4>
<pre>#!/usr/bin/env zsh<br /><br />if [ -f "${HOME}/.kube/config-xxxx" ]; then<br /> export KUBECONFIG=${HOME}/.kube/config-xxxx<br />fi<br /><br />pods=( $(kubectl get pod -n mynamespace | egrep -o "myapp-deployment-[a-zA-Z0-9-]+") )<br /><br />_sleep=<br />for pod in "${pods[@]}" ; do<br /> ${_sleep}<br /> kubectl -n mynamespace delete pod ${pod}<br /> _sleep="sleep 10s"<br />done</pre>
