Saturday, June 15, 2024

Deploying Your First Docker Image Using Kubernetes: A Step-by-Step Guide

 Deploying Your First Docker Image Using Kubernetes: A Step-by-Step Guide










Deploying a Docker image via Kubernetes can seem daunting at first, but with this comprehensive guide, you'll be able to deploy your first Docker image with ease. Follow these steps to get your application up and running using Kubernetes and Minikube.

Prerequisites

Before starting, make sure you have kubectl and Minikube installed on your local machine. Verify the installations by executing the following commands:

  • command: kubectl version --client 
  • command: minikube status
If you have not already installed Minikube and kubectl, or if you encounter errors, refer to our installation guide: Introduction to Kubernetes and Minikube Installation.



Step-by-Step Guide to Deploying via Kubernetes

1. Create a Deployment

First, you need to create a deployment. Use the following command, replacing deploymentName with your desired deployment name and imageName with your Docker image name:

command: kubectl create deployment deploymentName --image=imageName


2. Verify the Deployment

To ensure that your deployment and pods are running, execute:

  • command: kubectl get deployments
  • command: kubectl get pods




3. Bind the Port

Next, bind the port. Assuming your Docker image exposes port 3000 internally, you can expose this port externally using the following command

command:kubectl expose deployment deploymentName --type=LoadBalancer --port=3000


4. Notify Minikube

Finally, inform Minikube about the service. This will provide you with a URL to access your application. Run:
command: minikube service deploymentName



Copy the provided URL and paste it into your browser to see your application in action.


Copy the provided URL and paste it into your browser to see your application in action.


Rolling Out Updates

Once your application is deployed, you might need to update it. Rolling out updates in Kubernetes is straightforward. Use the following command to update your deployment with a new image version:


command: kubectl set image deployment deploymentName containerName=newImageName:newTag

Verify the rollout status with the command: kubectl rollout status deployment deploymentName



now  you can see on the same service/url my updated image is running



Rolling Back Updates

If something goes wrong with your update, you can easily roll back to the previous version. Use the following command to roll back the deployment:

command:kubectl rollout undo deployment/deploymentName


after running the rollout undo command hit your Project URL again you will see your project is rolled back to the previous version




Conclusion

By following these steps, you can easily deploy your first Docker image using Kubernetes and Minikube. This guide helps streamline the process, ensuring a successful deployment. With these foundational skills, you can explore more advanced features of Kubernetes and enhance your containerized applications further.

For more detailed information on Kubernetes and Docker, check out our other blog posts and tutorials. Happy deploying!






Previous Post
Next Post

post written by:

0 comments: