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 kubectl rollout restart command:
$ kubectl rollout restart <controller_type> <controller_name>
Run in Warp
Where:
- controller_type is the type of controller, such as deployment or daemonset.
- controller_name is the name of the controller.
For example:
$ kubectl rollout restart deployment myDeployment
Run in Warp
Upon execution, the above command will perform a rolling restart of the Deployment named myDeployment, 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 retrieve this command using Warp’s AI Command Suggestions
If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:
Entering k8s restart in the AI Command Suggestions will prompt a kubectl command, which can be inserted quickly into your shell by doing CMD+ENTER.
Performing a rollout restart of 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 kubectl rollout restart deployment command as follows:
$ kubectl rollout restart deployment <name>
Run in Warp
Where:
- name is the name of the Deployment to restart.
For example:
$ kubectl rollout restart deployment myDeployment
Run in Warp
Upon execution, the above command will perform a rollout restart of the Deployment named myDeployment , 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 kubectl get deployment command.
Restarting all Deployments at once
To restart all the Deployments in your Kubernetes cluster simultaneously, you can use the kubectl rollout restart deploy command:
$ kubect rollout restart deploy
Run in Warp
Restarting all Deployments by labels
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 kubectl rollout deploy command with -l (short for --label) flag as follows:
$ kubectl rollout restart deploy -l <label>
Run in Warp
For example:
$ kubectl rollout restart deploy -l mypp=nginx
Run in Warp
Upon execution, the above command will restart all the Deployments available in the specified namespace, thus terminating old Pods and recreating new ones.
Performing a rollout restart of 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 kubectl rollout restart statefulset command as follows:
$ kubectl rollout restart statefulset <name>
Run in Warp
Where:
- name is the name of the StatefulSet to restart.
For example:
$ kubectl rollout restart statefulset mySet
Run in Warp
Upon execution, the above command will initiate a rollout restart of the StatefulSet named mySet, 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 kubectl get statefulset command.
Performing a rollout restart of 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 kubectl rollout restart daemonset command as follows:
$ kubectl rollout restart daemonset <name>
Run in Warp
Where:
- name is the name of the DaemonSet to restart.
For example:
$ kubectl rollout restart daemonset myDaemon
Run in Warp
Upon execution, the above command will initiate a rollout restart for the DaemonSet named myDaemon, 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 kubectl get daemonset command.
Restarting 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 kubectl rollout restart 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 kubectl rollout restart command followed by the -n (short for --namespace) flag as follows:
$ kubectl rollout restart <controller_type> <controller_name> -n <namespace>
Run in Warp
Where:
- controller_type is the type of controller, such as deployment or daemonset.
- controller_name is the name of the controller.
- namespace is the name of the namespace.
For example:
$ kubectl rollout restart deployment myDeployment -n myNamespace
Run in Warp
Upon execution, the above command will perform a rolling restart for the Pods within Deployment named myDeployment, associated with the specified namespace myNamespace.
Watching the rollout restart status
To watch the progress of a rollout restart, you can use the kubectl rollout status command that continuously monitors the status of the latest rollout:
>$ kubectl rollout status <controller_type> <controller_name>
Run in Warp
Where:
- controller_type is the type of controller, such as deployment or daemonset.
- controller_name 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
Run in Warp
Upon execution, the above command will output the current status of the latest rollout for the Deployment named myDeployment.
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.
Written by
Mansi Manhas
Filed Under
Related Articles
Copy Files From Pod in Kubernetes
Learn how to copy files and directories from within a Kubernetes Pod into the local filesystem using the kubectl command.
Scale Deployments in Kubernetes
Learn how to manually and automatically scale a Deployment based on CPU usage in Kubernetes using the kubectl-scale and kubectl-autoscale commands.
Get Kubernetes Logs With kubectl
Learn how to get the logs of pods, containers, deployments, and services in Kubernetes using the kubectl command. Troubleshoot a cluster stuck in CrashloopBackoff, ImagePullBackoff, or Pending error states.
Forward Ports In Kubernetes
Learn how to forward the ports of Kubernetes resources such as Pods and Services using the kubectl port-forward command.
Tail Logs In Kubernetes
Learn how to tail and monitor Kubernetes logs efficiently to debug, trace, and troubleshoot errors more easily using the kubectl command.
Get Context In Kubernetes
Learn how to get information about one or more contexts in Kubernetes using the kubectl command.
Delete Kubernetes Namespaces With kubectl
Learn how to delete one or more namespaces and their related resources in a Kubernetes cluster using the kubectl command.
Get Kubernetes Secrets With kubectl
Learn how to list, describe, customize, sort and filter secrets in a Kubernetes cluster by name, type, namespace, label and more using the kubectl command.
List Kubernetes Namespaces With kubectl
Learn how to list, describe, customize, sort and filter namespaces in a Kubernetes cluster by name, label, and more using the kubectl command.
How To List Events With kubectl
Learn how to list and filter events in Kubernetes cluster by namespace, pod name and more using the kubectl command.
Kubernetes vs Docker: The Backbone of Modern Backend Technologies
Lean the fundamentals of the Kubernetes and Docker technologies and how they interplay with each other.
Set Context With kubectl
Learn how to create, modify, switch, and delete a context in Kubernetes using the kubectl config command.