DEV Community

Faris Durrani
Faris Durrani

Posted on

How to Restart a Kubernetes Deployment on OKE

Say you followed my instructions to deploy a React app to Oracle Cloud's Kubernetes Engine (OKE).

But now you've made some changes to your code and you want OKE to restart the Docker container with the latest code.

Assuming you've pushed the latest code to the Oracle Cloud Container Registry (see instructions here) and you have local access to your OKE cluster through kubectl, we can restart the running container.

Safe restart using rollout

This safe command will attempt to pull the latest Docker images from Container Registry and run them. On success, the old pods that run the old containers will be destroyed and replaced with the new one. On failure, the old pods remains running.

kubectl rollout restart deployment.apps/myApp
Enter fullscreen mode Exit fullscreen mode

where:

  • deployment.apps/myApp is the name of your app deployment which you can find using kubectl get all

The status of the rollout can be checked using:

kubectl rollout status deployment.apps/myApp
Enter fullscreen mode Exit fullscreen mode

or:

kubectl get all
Enter fullscreen mode Exit fullscreen mode

Force restart using delete

To forcefully destroy (delete) the currently running containers and restart them using the latest images, run:

kubectl delete pod/myApp-6c789d5720-9fgia
Enter fullscreen mode Exit fullscreen mode

where:

  • pod/myApp-6c789d4595-7hftd is the name of the pod of your container found using kubectl get all.

You will have to run this command for all the pods of the running application deployment. Kubernetes is designed to manage multiple running replicas of the same application images, depending on the number of replicas you put in deployment.yaml.

You can also elect to delete all running pods using:

kubectl delete --all pods
Enter fullscreen mode Exit fullscreen mode

Warning: Between the time the containers are destroyed and the new containers are successfully running, the deployment will be offline. This can be permanent if the new containers never successfully build. Use the previous command to safely restart the deployment instead if possible.


Detail: I may be interchanging terminologies between deployment, pod, and container, in which case please let me know a better way to rephrase my sentences.

Safe harbor statement
The information provided on this channel/article/story is solely intended for informational purposes and cannot be used as a part of any contractual agreement. The content does not guarantee the delivery of any material, code, or functionality, and should not be the sole basis for making purchasing decisions. The postings on this site are my own and do not necessarily reflect the views or work of Oracle or Mythics, LLC.

This work is licensed under a Creative Commons Attribution 4.0 International License.

Top comments (0)