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

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 ...

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-p...

Maven Repositories (local, central, global)

Maven relies on repositories to manage dependencies, plugins, and other artifacts required for a project. There are typically three types of repositories in Maven: local, central, and remote/global repositories. Local Repository: Location: The local repository is located on your local development machine. By default, it's in the .m2 directory within your user home directory (e.g., C:\Users\<username>\.m2\repository on Windows or /Users/<username>/.m2/repository on macOS and Linux). Purpose: The local repository is used to store artifacts (JARs, POMs, and other files) that your machine has downloaded or built during previous Maven builds. These artifacts are specific to your local development environment. Benefits: Using a local repository improves build performance since it caches dependencies locally, reducing the need to download them repeatedly. It also ensures reproducibility by maintaining a local copy of dependencies. Central Repository: Location: The central repo...