Terminus by Warp
Perform Rollout Restarts With kubectl

Perform Rollout Restarts With kubectl

 Mansi Manhas
Mansi Manhas

In Kubernetes, a rollout restart is a process that updates the Pod's configuration, such as containers, ports, and environment variables, by creating new Pods with the updated settings and removing the old ones, one by one, ensuring uninterrupted service. This process is supported for Kubernetes controllers, including Deployment, StatefulSet, and DaemonSet. These controllers enable various actions related to Pod management, such as deployment, scaling, updating pods, and more.

The short answer

To perform a rollout restart of Kubernetes controllers, you can use the [.inline-code]kubectl rollout restart[.inline-code] command:

$ kubectl rollout restart <controller_type> <controller_name>

Where:

  • [.inline-code]controller_type[.inline-code] is the type of controller, such as [.inline-code]deployment[.inline-code] or [.inline-code]daemonset[.inline-code].
  • [.inline-code]controller_name[.inline-code] is the name of the controller.

For example:

$ kubectl rollout restart deployment myDeployment

Upon execution, the above command will perform a rolling restart of the Deployment named [.inline-code]myDeployment[.inline-code], removing and recreating its Pods one by one, ensuring zero downtime and maintaining the application’s availability.

Note that this command is available only for Kubernetes version 1.15 and higher.

If you want to learn more about restarting Pods, you can read our other article on how to restart a Pod in Kubernetes.

[#easily-recall-with-ai] Easily retrieve this command using Warp’s AI Command Suggestions [#easily-recall-with-ai]

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

Entering [.inline-code]k8s restart[.inline-code] in the AI Command Suggestions will prompt a [.inline-code]kubectl[.inline-code] command, which can be inserted quickly into your shell by doing [.inline-code]CMD+ENTER[.inline-code].

[#rollout-restart-a-deployment] Performing a rollout restart of a Deployment [#rollout-restart-a-deployment]

In Kubernetes, a Deployment is used to manage and provide declarative updates to the Pods. This command will be helpful when you want to manage applications that involve multiple Deployments and require frequent updates, such as configuration updates or pulling a new container image.

To restart the Pods within a Deployment, you can use the [.inline-code]kubectl rollout restart deployment[.inline-code] command as follows:

$ kubectl rollout restart deployment <name>

Where:

  • [.inline-code]name[.inline-code] is the name of the Deployment to restart.

For example:

$ kubectl rollout restart deployment myDeployment

Upon execution, the above command will perform a rollout restart of the Deployment named [.inline-code]myDeployment[.inline-code] , terminating and recreating the Pods within it.

To check if all the Pods in a Deployment have completed the restart process, you can use the [.inline-code]kubectl get deployment[.inline-code] command.

[#restart-all-deployments] Restarting all Deployments at once [#restart-all-deployments]

To restart all the Deployments in your Kubernetes cluster simultaneously, you can use the [.inline-code]kubectl rollout restart deploy[.inline-code] command:

$ kubect rollout restart deploy

[#restart-all-deployments-by-label] Restarting all Deployments by labels [#restart-all-deployments-by-label]

In Kubernetes, labels are key-value pairs that can be attached to various Kubernetes resources. These labels identify and organize the resources in larger Kubernetes environments.

To restart all the Deployments associated with specific labels, you can use the [.inline-code]kubectl rollout deploy[.inline-code] command with [.inline-code]-l[.inline-code] (short for [.inline-code]--label[.inline-code]) flag as follows:

$ kubectl rollout restart deploy -l <label>

For example:

$ kubectl rollout restart deploy -l mypp=nginx

Upon execution, the above command will restart all the Deployments available in the specified namespace, thus terminating old Pods and recreating new ones.

[#rollout-restart-a-statefulset] Performing a rollout restart of a StatefulSet [#rollout-restart-a-statefulset]

In Kubernetes, a StatefulSet is a controller used for managing the deployment of Pods, especially for stateful applications such as databases. It retains the state and identity of each Pod during updates or restarts.

To restart the Pods within a StatefulSet, you can use the [.inline-code]kubectl rollout restart statefulset[.inline-code] command as follows:

$ kubectl rollout restart statefulset <name>

Where:

  • [.inline-code]name[.inline-code] is the name of the StatefulSet to restart.

For example:

$ kubectl rollout restart statefulset mySet

Upon execution, the above command will initiate a rollout restart of the StatefulSet named [.inline-code]mySet[.inline-code], terminating and recreating the Pods within it.

To check if all the Pods in a StatefulSet have completed the restart process, you can use the [.inline-code]kubectl get statefulset[.inline-code] command.

[#rollout-restart-a-daemonset] Performing a rollout restart of a DaemonSet [#rollout-restart-a-daemonset]

In Kubernetes, a DaemonSet is a controller used to ensure that a copy of your application is running on every node in your Kubernetes cluster. For example, running a cluster storage daemon or running a logs collection daemon on every node. 

To restart the Pods within a DaemonSet, you can use the [.inline-code]kubectl rollout restart daemonset[.inline-code] command as follows:

$ kubectl rollout restart daemonset <name>

Where:

  • [.inline-code]name[.inline-code] is the name of the DaemonSet to restart.

For example:

$ kubectl rollout restart daemonset myDaemon

Upon execution, the above command will initiate a rollout restart for the DaemonSet named [.inline-code]myDaemon[.inline-code], terminating and recreating the Pods within the specified DaemonSet.

To check if all the Pods in a DeamonSet have completed the restart process, you can use the [.inline-code]kubectl get daemonset[.inline-code] command.

[#restart-controllers-in-a-namespace] Restarting controllers in a namespace [#restart-controllers-in-a-namespace]

In Kubernetes, namespaces provide a logical way to separate resources within an application, forming isolated virtual clusters within the Kubernetes cluster.

By default, the [.inline-code]kubectl rollout restart[.inline-code] command will initiate the restart of the controllers in your current namespace.

To perform a rollout restart of the Pods in any other namespace, you can use the [.inline-code]kubectl rollout restart[.inline-code] command followed by the [.inline-code]-n[.inline-code] (short for [.inline-code]--namespace[.inline-code]) flag as follows:

$ kubectl rollout restart <controller_type> <controller_name> -n <namespace>

Where:

  • [.inline-code]controller_type[.inline-code] is the type of controller, such as [.inline-code]deployment[.inline-code] or [.inline-code]daemonset[.inline-code].
  • [.inline-code]controller_name[.inline-code] is the name of the controller.
  • [.inline-code]namespace[.inline-code] is the name of the namespace.

For example:

$ kubectl rollout restart deployment myDeployment -n myNamespace

Upon execution, the above command will perform a rolling restart for the Pods within Deployment named [.inline-code]myDeployment[.inline-code], associated with the specified namespace [.inline-code]myNamespace[.inline-code].

[#watch-the-rollout-restart-status] Watching the rollout restart status [#watch-the-rollout-restart-status]

To watch the progress of a rollout restart, you can use the [.inline-code]kubectl rollout status[.inline-code] command that continuously monitors the status of the latest rollout:

>$ kubectl rollout status <controller_type> <controller_name>

Where:

  • [.inline-code]controller_type[.inline-code] is the type of controller, such as [.inline-code]deployment[.inline-code] or [.inline-code]daemonset[.inline-code].
  • [.inline-code]controller_name[.inline-code] is the name of the controller.

For example:

$ kubectl rollout status deployment myDeployment
Waiting for deployment "myDeployment" rollout to finish: 2 out of 3 new replicas have been updated…
Waiting for deployment "myDeployment" rollout to finish: 1 old replicas are pending termination...
deployment "myDeployment" successfully rolled out

Upon execution, the above command will output the current status of the latest rollout for the Deployment named [.inline-code]myDeployment[.inline-code].

This command can also help you in identifying potential issues, such as a stuck rollout or failed pods, during the rollout restart process. You can refer to the official documentation to learn more about the supported flags.

Experience the power of Warp

  • Write with an IDE-style editor
  • Easily navigate through output
  • Save commands to reuse later
  • Ask Warp AI to explain or debug
  • Customize keybindings and launch configs
  • Pick from preloaded themes or design your own
brew install --cask warp
Copied!
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist or join the Windows waitlist
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.