Welcome to another hands-on tutorial! Today, we’re deploying a custom HTTPD application in a Kubernetes cluster using Minikube. Follow along as we walk through each step, from setting up prerequisites to deploying, scaling, and cleaning up our application. By the end, you’ll have an in-depth understanding of deploying Docker applications in Minikube with Kubernetes.
Prerequisites: Setting Up Your Environment
Before we start, make sure you have these tools installed and configured on your local machine:
- Docker (to build and run container images)
- kubectl (to manage Kubernetes clusters)
- Minikube (to run a Kubernetes cluster locally)
To verify each tool, use the following commands:
Step 1: Run Docker Without Sudo
For convenience, we’ll configure Docker to run without sudo
:
After running these commands, log out and back in or use newgrp docker
to apply the changes.
Step 2: Start the Minikube Cluster and Set Docker Environment to Minikube
Next, configure your Docker environment to use Minikube’s Docker daemon:
This allows Minikube to directly access any images you build.
Step 3: Create a Custom HTTPD Docker Image
1. Set Up Project Directory and HTML File
First, create a project directory and an HTML file that will serve as our homepage.
2. Create a Dockerfile
Now, create a Dockerfile with the following content to build our HTTPD image:
This Dockerfile uses the HTTPD base image and copies our custom index.html
file into the appropriate directory.
3. Build the Docker Image
Build and tag the custom Docker image:
Step 4: Create a Kubernetes Deployment
Create a deployment.yaml
file with the following configuration to deploy your application:
This file defines a deployment with one replica of our custom HTTPD application.
Apply the Deployment
Step 5: Expose the Deployment
To access the application externally, expose the deployment using a NodePort service:
Step 6: Get the Minikube Service URL
Retrieve the service URL to access your HTTPD application:
Open this URL in your browser to view the application.
Step 7: Check Pod Status
Verify that the pods are running as expected:
Step 8: Scaling the Deployment
Scale Up
Increase the number of replicas to 5:
Scale Down
Decrease replicas to 2:
Step 9: Simulate Pod Failure
Delete a pod to see Kubernetes automatically recreate it:
Replace <pod-name>
with the name of a running pod to observe Kubernetes’ self-healing capabilities.
Step 10: Clean Up
Finally, delete the service and deployment:
Conclusion
Congratulations! You've successfully deployed, scaled, and managed a custom HTTPD application in Minikube. This exercise provided a solid foundation in deploying applications on Kubernetes locally with Minikube.
If you found this tutorial helpful, stay tuned for more Kubernetes guides! Don’t forget to like, share, and subscribe for updates.
Comments
Post a Comment