Table of Contents
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 Rollout Restart: 3 Ways to Use It
- Kubectl Get Context: Its Uses and How to Get Started
- Kubectl Get Nodes: Why and How to Use It
- Kubectl Proxy: When and How to Use it to Access the Kubernetes API
- Kubectl Patch: What You Can Use It for and How to Do It
- How to Restart Pods in Kubectl: A Tutorial With Examples
- Kubectl Login: Solving Authentication For Kubernetes
- Kubectl Exec: Everything You Need to Know
- Installing and Managing kubectl Plugins with Krew
#What Is 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.
#How To Use It
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:
- Make changes to your code base.
- Build and push a new docker image.
- Update your deployments config to use the new image.
- 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
#Kubectl Rollout Restart: 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) 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.
#2) Preventing StatefulSets From Exceeding Limits
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) Maintaining a Reliable Environment
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.
#Things To Know 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.
#Third-Party Options and Using Other Command Lines
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.
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 : Check out vCluster
#Additional Articles You May Like:
- How to Build an Internal Kubernetes Platform
- Docker Compose to Kubernetes: Step-by-Step Migration
- How to Create and Manage Kubernetes Secrets: A Tutorial
- Kubernetes Virtual Clusters
- A Hands-on Tutorial - Kubernetes Virtual Clusters
- Kubernetes Multi-Tenancy – A Best Practices Guide
- Kubernetes Cost Optimization with Virtual Clusters
- A Complete Guide to Kubernetes Cost Optimization
- How To Reduce Your Kubernetes Cost
- Kubernetes Namespaces vs. Virtual Clusters
- 10 Essentials For Kubernetes Multi-Tenancy
- Kubernetes: Virtual Clusters For CI/CD & Testing
- Virtual Clusters For Kubernetes - Benefits & Use Cases
- Kubernetes Multitenancy: Why Namespaces aren’t Good Enough
- Kubernetes Multi-Tenancy with Argo CD And Loft
- Kubernetes Multi-Tenancy: Why Virtual Clusters Are The Best Solution
- [Video] Beyond Namespaces: Virtual Clusters are the Future of Multi-Tenancy