What You’ll Need
- An Ubuntu system
- Basic knowledge of the command line
- Installed tools: `curl`, `apt-transport-https`, `virtualbox` (or another virtualization tool)
Step 1: Prepare Your Environment
First, let’s ensure your system is up-to-date and has the necessary packages.
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl apt-transport-https virtualbox
Step 2: Install Minikube
Minikube is a tool that makes it easy to run Kubernetes locally. Here’s how to install it:
1. Download the Minikube binary:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
2. Install Minikube:
sudo install minikube-linux-amd64 /usr/local/bin/minikube
3. Verify the installation:
minikube version
Step 3: Install kubectl
`kubectl` is the command-line tool used to interact with Kubernetes. Let’s install it:
1. Download the kubectl binary:
curl -LO -L "https://dl.k8s.io/release/$(curl -s -L https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
2. Install kubectl:
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
3. Verify the installation:
kubectl version --client
Step 4: Start Minikube
Now that you have Minikube and kubectl installed, let’s start your Minikube cluster.
1.Start Minikube:
minikube start
2. Check the status:
minikube status
Step 5: Create Your Custom `index.html`
Next, we’ll create a simple `index.html` file that our HTTP server will serve.
1.Create a directory for your HTML file:
mkdir ~/my-httpd
cd ~/my-httpd
2. Create the `index.html` file:
echo "<html><h1>Hello from My Custom HTTPD</h1></html>" > index.html
Step 6: Create a Dockerfile
Now, we need to package our `index.html` file into a Docker image using a `Dockerfile`.
1. Create the Dockerfile with following using vi/nano/any IDE:
FROM httpd:2.4
COPY index.html /usr/local/apache2/htdocs/" > Dockerfile
2. Build the Docker image:
Ensure Docker is available in Minikube:
eval $(minikube docker-env)
docker build -t my-httpd-image .
Step 7: Deploy Your HTTPD Application
With the Docker image ready, let’s deploy it to our Kubernetes cluster.
1.Create a deployment:
kubectl create deployment my-httpd --image=my-httpd-image
2. Expose the deployment:
kubectl expose deployment my-httpd --type=NodePort --port=80
Step 8: Access Your Application
Now it’s time to access your custom HTTP server!
Method 1: Using Minikube IP
1. Get the Minikube IP address:
minikube ip
2. Access the service:
Use the URL you get from:
minikube service my-httpd --url
Open this URL in your web browser.
Method 2: Using a Tunnel for Localhost Access
For direct access via `localhost`:
1.Open a new terminal and run:
minikube tunnel
(You might need elevated privileges for this.)
2. Access your service:
Now you can access your HTTPD service at:
http://localhost:80
Step 9: Stop and Delete Minikube Cluster
When you’re done, you can stop and delete the Minikube cluster.
1. Stop the cluster:
minikube stop
2. Delete the cluster:
minikube delete
Conclusion
Congratulations! You’ve successfully set up a Kubernetes cluster using Minikube, deployed a custom Apache HTTP server, and accessed it both via Minikube's IP and `localhost`. This exercise lays the foundation for exploring more advanced Kubernetes features. If you have any questions or want to dive deeper, feel free to reach out or leave a comment! Happy Kubernetes learning!
Comments
Post a Comment