Kubectl Rollout Restart: Orchestrating Kubernetes Deployments
How kubectl rollout restart replaces pods, when to use it, how to check and undo a rollout, and how to automate restarts with verification and alerts.
TL;DR —
kubectl rollout restarttriggers a rolling restart of a Deployment, DaemonSet, or StatefulSet. It sets arestartedAtannotation on the pod template, so the controller replaces pods gradually while respecting readiness probes and the rollout strategy. Pair it withkubectl rollout statusto confirm the restart actually finished.
Managing applications in Kubernetes often requires updating their underlying configuration or environment without disrupting service. Changing a ConfigMap or Secret never recreates pods: environment variables keep the old value until the pod restarts, and mounted files update in place, but the app sees the change only if it rereads them. A full refresh is sometimes necessary to ensure all application instances reflect the latest state. Manually orchestrating this process across multiple deployments can be error-prone and time-consuming.
This article covers kubectl rollout restart, the command for controlled restarts in Kubernetes. It explains how it works, practical applications, and common troubleshooting steps. We’ll also show how to run it as an automated workflow that verifies the rollout and alerts the team.
How kubectl rollout restart replaces pods
The kubectl rollout restart command replaces your application’s pods gradually instead of all at once. Unlike manually deleting pods, which can interrupt service, a rollout restart uses the Deployment rolling-update strategy.
How Pod Template Annotations Drive Rolling Updates
When you execute kubectl rollout restart deployment/my-app, Kubernetes doesn’t actually “restart” anything in the traditional sense. Instead, it updates an annotation within the deployment’s pod template: kubectl.kubernetes.io/restartedAt. The value is set to the current timestamp.
This seemingly minor change is the key. The Deployment controller constantly monitors the pod template. When it detects a change, even in the metadata, it considers the template to be new. This triggers the standard rolling update process, just as if you had changed the container image or an environment variable.
Ensuring Application Availability with ReplicaSets
The rolling update process is managed through ReplicaSets. Here’s how it works:
- New ReplicaSet Creation: The Deployment controller creates a new ReplicaSet based on the updated pod template.
- Pod Scaling: The new ReplicaSet begins to scale up, creating new pods with the updated configuration.
- Health Checks: Kubernetes waits for the new pods to pass their readiness probes, ensuring they are healthy and ready to serve traffic.
- Old Pod Termination: As new pods become ready, the controller scales down the old ReplicaSet, terminating the old pods.
This process respects the maxUnavailable and maxSurge parameters defined in your Deployment’s strategy, ensuring that a minimum number of healthy pods are always available to handle requests.
Availability depends on the workload. A Deployment with readiness probes keeps serving. A single-replica StatefulSet is down while its pod is recreated. In-flight requests survive only if the app handles SIGTERM within terminationGracePeriodSeconds or has a preStop hook. PodDisruptionBudgets do not limit rolling updates.
Why Manual Kubernetes Rollouts Fall Short in Production
Running kubectl rollout restart by hand in a production environment introduces several risks and inefficiencies:
- Lack of Traceability: Manual commands are not inherently audited. It’s difficult to track who initiated a restart, why, and when, which is critical for compliance and incident response.
- No Scheduling or Event-Driven Logic: You can’t schedule a restart for off-peak hours or trigger it automatically in response to an event, like a secret rotation or a monitoring alert.
- No Automated Verification: The command itself doesn’t wait for the rollout to complete successfully. A separate
kubectl rollout statuscommand is required, and there’s no built-in logic to handle timeouts or failures. - Human Error: Manual processes are prone to errors, such as targeting the wrong deployment or namespace, leading to unintended consequences.
- Integration Challenges: It’s difficult to chain restarts with other operations, like updating a database schema, clearing a cache, or sending notifications, without custom scripting.
To address these limits, teams turn to workflow orchestration tools that can encapsulate these operations into reliable, automated processes. This is a core aspect of modern job orchestration.
Orchestrate Kubernetes Deployments with Kestra: Automated Rollout and Verification
Orchestration platforms like Kestra can automate the entire restart process, adding verification, error handling, and notifications. This turns a manual CLI command into a governed, event-driven workflow.
Consider a scenario where you need to restart a deployment after a configuration change. The following Kestra flow can be triggered by a webhook from your CI/CD system. It restarts the deployment, waits for it to complete, and sends a Slack notification.
id: k8s-rollout-restart-and-verifynamespace: company.ops
triggers: - id: on_config_change type: io.kestra.plugin.core.trigger.Webhook key: "{{ secret('ROLLOUT_WEBHOOK_KEY') }}"
tasks: - id: restart_deployment type: io.kestra.plugin.kubernetes.kubectl.Restart connection: masterUrl: "{{ secret('MASTER_URL') }}" caCertData: "{{ secret('CA_CERT_DATA') }}" oauthToken: "{{ secret('OAUTH_TOKEN') }}" namespace: my-app-ns resourceType: Deployment resourcesNames: - my-app-deployment
- id: check_rollout_status type: io.kestra.plugin.scripts.shell.Commands taskRunner: type: io.kestra.plugin.scripts.runner.docker.Docker # Any image with a shell and kubectl; pin the tag that matches your cluster's version containerImage: alpine/kubectl:latest inputFiles: kubeconfig: "{{ secret('KUBECONFIG') }}" env: KUBECONFIG: kubeconfig commands: - kubectl rollout status deployment/my-app-deployment -n my-app-ns --timeout=5m
- id: notify_success type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook url: "{{ secret('SLACK_WEBHOOK_URL') }}" payload: | {"text": "Deployment my-app-deployment in my-app-ns restarted and rolled out (execution {{ execution.id }})."}
errors: - id: notify_failure type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook url: "{{ secret('SLACK_WEBHOOK_URL') }}" payload: | {"text": "Restart of my-app-deployment in my-app-ns failed or timed out. Check execution {{ execution.id }}."}Point both tasks at the same cluster: Restart connects with the connection secrets, and the status check reads a kubeconfig stored as a Kestra secret, so both must target the same API server.
What’s worth noticing in this workflow:
- Declarative Restart: The
kubectl.Restarttask names the resource to restart, so the action is explicit and recorded. - Blocking Status Check:
kubectl rollout statusruns in a separate shell task. With--timeout, it either succeeds when the rollout completes or fails when the timeout expires, which sends the failure alert.kubectl.Restartreturns as soon as the annotation is patched (itswaitUntilReadyis ignored), so the status check is what fails the run when pods never become ready. - Automated Notifications: The flow automatically sends a success or failure notification to Slack, providing immediate feedback without manual intervention.
- Centralized Auditing: Every execution is logged in Kestra, providing a complete audit trail of who triggered the restart and the outcome. This is especially useful for automating remediation from alerts.
Beyond Deployments: Applying kubectl rollout restart to Other Kubernetes Resources
The kubectl rollout restart command is not limited to Deployments. It can also be used with DaemonSets and StatefulSets, though with some differences in behavior.
Restarting DaemonSets for Node-Level Updates
For DaemonSets, kubectl rollout restart daemonset/<name> triggers a rolling update across all nodes where the DaemonSet’s pods are running. This is useful for applying node-level configuration changes, such as updating a logging agent or a monitoring tool. Kestra’s kubectl.Restart task supports Deployments and StatefulSets; for DaemonSets, run kubectl rollout restart daemonset/<name> in a Commands task like check_rollout_status above.
Managing StatefulSets with Controlled Restarts
When used with a StatefulSet (kubectl rollout restart statefulset/<name>), the restart follows the StatefulSet’s ordered update guarantees. Pods are restarted one at a time, in reverse ordinal order (e.g., pod-2, then pod-1, then pod-0). The controller waits for each pod to become ready before moving to the next one, ensuring the stability of stateful applications like databases or message queues.
Ready to orchestrate your infrastructure?
Essential Troubleshooting and Rollback with kubectl rollout undo
Even with controlled rollouts, things can go wrong. A new configuration might be invalid, or a new pod might fail its readiness probe. Kubernetes provides commands to inspect and revert rollouts.
To view the history of a deployment’s revisions, use:
kubectl rollout history deployment/my-app-deploymentIf you detect a problem after a restart, you can revert to the previous revision using kubectl rollout undo:
kubectl rollout undo deployment/my-app-deploymentundo starts another rolling replacement using the previous pod template. After a restart, that template differs only by the restartedAt annotation, so undo restarts the pods again without changing what they run. If the restart surfaced a bad ConfigMap value, revert the ConfigMap and restart. For more complex failure scenarios, you can build automated rollback workflows, as shown in the Kubernetes Failed Rollout Auto-Rollback blueprint.
Where Automated Kubernetes Rollouts Pay Off
Automating kubectl rollout restart in an orchestrator covers several use cases:
- Secret and ConfigMap Rotation: Automatically restart deployments when their configuration changes in Vault, Git, or another source of truth. The Rotate Vault Secrets into Kubernetes blueprint shows this pattern.
- Periodic Application Refreshes: Schedule nightly or weekly restarts to clear memory leaks, refresh caches, or recycle connections in legacy applications.
- Self-Healing Infrastructure: Trigger a restart automatically in response to monitoring alerts from Prometheus or other systems, creating a basic self-healing infrastructure.
- GitOps Integration: Integrate restarts into a GitOps pipeline, ensuring that configuration changes applied via Git are safely rolled out to the cluster.
By moving beyond manual commands, you can build a more resilient and automated infrastructure control plane.
Related Concepts
- Kestra for Kubernetes Orchestration
- Kubernetes Job Orchestration
- Building Kubernetes Workflows
- The Kestra Kubernetes Plugin
- Managing Retries and Restarts with Subflow Executions
To learn more about how Kestra can help you manage your entire infrastructure, visit the Infrastructure Automation page.
Terraform, Ansible and Kubernetes, orchestrated from one place.
Related resources
Frequently asked questions
Find answers to your questions right here, and don't hesitate to Contact Us if you couldn't find what you're looking for.