Skip to main content

Setting Up a Custom HTTPD Server on Kubernetes with Minikube on Ubuntu

In this article, we’ll walk through the steps to set up a Kubernetes cluster on Ubuntu using Minikube and deploy a custom Apache HTTP server (`httpd`) with your own `index.html` file. Whether you’re a beginner or just looking to refresh your skills, this guide will help you get started with Kubernetes and Docker.

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

Popular posts from this blog

Maven Create and Build Artifacts

In Maven, you can create and build artifacts using the package phase of the build lifecycle. The package phase is responsible for taking the compiled code and other project resources and packaging them into a distributable format, such as a JAR (Java Archive), WAR (Web Application Archive), or other custom formats. Here are the steps to create and build artifacts using Maven: Configure the Build Output: In your project's pom.xml file, you need to configure the output of the build. This includes specifying the type of artifact you want to create (e.g., JAR, WAR) and any additional resources to include. You do this in the <build> section of your pom.xml: <build>     <finalName>my-artifact</finalName> <!-- Name of the artifact without the extension -->     <plugins>         <!-- Plugin configurations for creating the artifact -->         <!-- For example, maven-jar-plugin or maven-war-plugin -->     </plugins> </build> Depend

Example of Maven project that interacts with a MySQL database and includes testing

Example Maven project that interacts with a MySQL database and includes testing To install Java, MySQL, Maven, and write a Java program to fetch table data, execute, and create a JAR file using Maven on Ubuntu, you can follow these steps: Step 1: Install Java You can install Java using the following commands: sudo apt update sudo apt install default-jre sudo apt install default-jdk Verify the installation by running: java -version Step 2: Install MySQL You can install MySQL using the following commands: sudo apt update sudo apt install mysql-server During the installation, you'll be prompted to set a root password for MySQL or you can set password at latter stage using following steps.  sudo mysql ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; exit Step 3: Install Maven You can install Maven using the following commands: sudo apt update sudo apt install maven Verify the installation by running: mvn -version Step 4: Create

Experiment No. 5 Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, and Local HTTP Server

  Experiment No. 5 Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, and Local HTTP Server  Objective: The objective of this experiment is to set up a CI/CD pipeline for a web development project using Jenkins, Git, and webhooks, without the need for a Jenkinsfile. You will learn how to automatically build and deploy a web application to a local HTTP server whenever changes are pushed to the Git repository, using Jenkins' "Execute Shell" build step. Introduction: Continuous Integration and Continuous Deployment (CI/CD) is a critical practice in modern software development, allowing teams to automate the building, testing, and deployment of applications. This process ensures that software updates are consistently and reliably delivered to end-users, leading to improved development efficiency and product quality. In this context, this introduction sets the stage for an exploration of how to apply CI/CD principles specifically to web development using J