Kubectl Rollout Restart: 3 Ways to Use It

Mercy Kibet
9 Minute Read

TL;DR:

  • Kubectl rollout restart is a useful feature for updating running pods in a StatefulSet without disrupting availability.
  • It can be used to deploy new applications, prevent StatefulSets from exceeding limits, and maintain a reliable environment.
  • The process involves making changes to the code base, building and pushing a new docker image, and updating deployment config.
  • Rollout restart can be used to restart pods one at a time in a deployment, ensuring a smooth update process.
  • Third-party tools and front ends can enhance the functionality of kubectl rollout restart for more complex scenarios.

When working with kubectl and rolling out a new app version, you need to know what to do when it breaks. Taking a step back, an update is a big deal for any production deployment. You might look for a way to keep your deployments on track without having to do anything. You need to leverage kubectl rollout restart because of its ability to orchestrate a successful rolling update without disrupting existing infrastructure.

Kubectl rollout restart is one of those newer Kubernetes features that make life easier for those managing clusters at scale. If you're unfamiliar with it, this post will show you what it is and how to use it.

Kubectl Series

Understanding the Purpose of Kubectl Rollout Restart

A rollout restart is a way to update running pods in a StatefulSet with new or updated configuration without disrupting the availability of running pods or services.

Kubectl rollout restart is what'll help solve this problem while keeping things stable. One of the most significant advantages of kubectl rollout restart is that it works as intended even in a turbulent environment. Managing dynamic environments allows managers to continue making out-of-the-box changes without worrying about downtime.

Kubectl rollout restart makes it simple to implement updates without a complete reboot in the middle of an environment. You can include the command in a scheduled job, making it easier to automate, which can be great for sporadic deployments.

Exploring the Functionality of Rollout Restart in kubectl

Rollout Restart in kubectl:

  • Rollout Process: It involves gradually recreating pods in a step-by-step manner.
  • kubectl Rollout Restart Command: This command is a part of kubectl that initiates a new rollout process.
  • Functionality: It allows for the management of various aspects of a rollout, with the restart command specifically used to trigger the start of a new rollout.

Step-by-Step Guide on How to Utilize Kubectl Rollout Restart

Because kubectl rollout restart operates at a cluster level, it doesn't need to interact directly with any pods. This means you don't have to worry about modifying or destroying existing pods before beginning the update process. The process works by installing a new pod version and deploying it across your cluster, two significant advantages over rolling updates on a pod level.

While the process is simple to execute, it isn't always easy to know which step to take. In this area, kubectl rollout restart can be a little confusing. But just as with any complex feature, there can be slight differences between versions and implementations. For this reason, I'd like to walk through typical kubectl rollout restart scenarios. Most of the time, all you'll need to do is follow these steps:

  1. Make changes to your code base.
  2. Build and push a new docker image.
  3. Update your deployments config to use the new image.
  4. Run kubectl rollout restart on the deployment in question.

Let's say you have a deployment named my-nginx with two replicas. The image it's running is nginx:1.7.9, and you just pushed a new image named nginx:1.7.10 to your docker registry.

To update your deployment to use the new image, run:

kubectl set image deployment/my-nginx nginx=nginx:1.7.10 

This will update the deployment to use the new image.

Next, you'll need to rollout restart the deployment for the changes to take effect:

kubectl rollout restart deployment/my-nginx 

This will kill and restart your pods, causing them to pull and use the new image.

If there are any issues with the new image, you can always rollback to the previous image:

kubectl rollout undo deployment/my-nginx 

Illustrating Kubectl Rollout Restart Through an Example

A power outage or other issue in the cloud will inevitably lead to downtime. Kubectl rollout restart enables you to configure your application to start up again if it goes down. This is useful for ensuring that something as simple as a website can be returned online quickly and easily.

The following are three ways you can use kubectl rollout restart.

1) Leveraging Rollout Restart for Deploying New Applications

When new applications fail, the last thing you want to do is wait until they’re fixed by another team member or until you receive an end-of-life reminder email. Kubectl rollout restart enables you to upload new applications to the Kubernetes cluster and specify a restart policy. If your application fails, it automatically restarts so you can get your work done.

A yellow chain
2) Managing StatefulSets Limits with Kubectl Rollout Restart

Selective deletion is a powerful technique often employed when deploying stateful applications that exceed the number of nodes or other resource limitations. When you run kubectl rolling retstart, it deletes stateful applications such as databases after a period of inactivity. As always, it’s essential to use caution when using this feature (and be sure to test thoroughly).

3) Ensuring Reliability with Kubectl Rollout Restart

Some jobs are critical to the function of an organization and require them to remain available. By enabling a Kubernetes rollout restart, you can ensure continuity of these jobs. The following example uses both node selectors and labels to enable this capability.

apiVersion: apps/v1 \# for versions before 1.9.0 use apps/v1beta2 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 template: metadata: labels: app: nginx spec: nodeSelector: app: nginx containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80 protocol: TCP restartPolicy: Always 

With a successful rollout, you should be able to use the job object in either the kubectl get or kubectl create commands. However, if there is a failure in the rollout, it will come back on its own after a short time.

alt_text

Key Points to Understand About Rollout Restart and StatefulSets

When installing a pod and deploying it, the system will check to see if the container has already been deployed. If this is the case, it'll ask you whether you'd like to overwrite it or not.

The kubectl rollout restart command will use the StatefulSet to restart the pods in your deployment one at a time. If you do not have a deployment with a StatefulSet defined, you can use kubectl rollout history to view the history of your deployment. You can then use the kubectl rollout undo command to roll back to a previous deployment.

Kubectl rollout restart throws an error if we have deployed a pod using the same name on the cluster before your redeployment, so always replace it with a new one.

If you have more than one pod in your deployment, this will mean that you'll also need to specify a new version for each of them. It's possible that you've already updated a pod by accident, and if so, kubectl rollout restart won't be able to tell which version is the wrong one. That's why you should update at least the version of a pod before exposing it to the entire cluster using kubectl rollout restart.

Exploring Alternative Options and Command Lines for Rollout Restart

If you're looking to use kubectl rollout restart in more scenarios, third-party tools can help, for example, the deployment commands in openapi.io. Here is an openapiset based on Kubernetes operations you can use to set up your deployments.

Use front ends for kubectl rollout restart, but you'll also need to make minor adjustments. For example, if you're using openapiset commands with kubectl interpolation, you'll have to add "interpolate” to the front of its arguments.

Summarizing the Benefits of Kubectl Rollout Restart

Kubectl rollout restart is an excellent way to reboot your application without going through the entire process of redeploying it. This can save time, especially if you're trying to fix a minor issue. Loft is a great tool to help you manage your kubectl rollout restart deployments. By using Loft, you can easily keep track of your deployments and get insights into how your application is performing. If you're looking for a way to improve your kubectl rollout restart efficiency, Loft is worth trying.

This post was written by Mercy Kibet. Mercy is a full-stack developer with a knack for learning and writing about new and intriguing tech stacks.

Next Step: Explore vCluster for Further Enhancements

Discover More Articles Related to Kubectl Rollout Restart:

Sign up for our newsletter

Be the first to know about new features, announcements and industry insights.