Creating a single-node cluster with Minikube

Kubernetes is an open-source platform that provides container orchestration services, making it easier to manage containers, networks, and storage. The platform makes it easier to deploy, manage, and scale containers, whether it’s on-premises, in the cloud, or in a hybrid environment.

One way to get started with Kubernetes is to create a single-node cluster using Minikube. Minikube is a tool that makes it easy to run Kubernetes locally on your laptop or desktop. It provides a quick and easy way to spin up a single-node cluster and start experimenting with Kubernetes.

In this article, we’ll look at how to create a single-node cluster with Minikube, starting with the prerequisites and ending with the deployment of a simple application.

Prerequisites

Before we start, there are a few prerequisites that you need to have in place.

  1. Virtualization Software: To run Minikube, you need a virtualization software such as VirtualBox, VMware Fusion, or Hyper-V. VirtualBox is a popular and free choice and is used in this article.
  2. Minikube: You can download Minikube from the Minikube GitHub page. It’s available for Windows, Mac, and Linux.
  3. Kubernetes CLI (kubectl): Minikube comes with a version of kubectl, but you can also install it manually if needed.

With these prerequisites in place, we’re ready to start setting up our Minikube cluster.

Starting Minikube

Starting Minikube is easy. All you need to do is run the following command:

minikube start

Minikube will start a virtual machine in VirtualBox, install Kubernetes, and set up a single-node cluster. The process may take a few minutes, depending on the speed of your computer.

When the process is complete, Minikube will display the following message:

“Starting cluster components… Kubectl is now configured to use the cluster.”

At this point, you have a single-node Kubernetes cluster up and running on your local machine. You can check the status of the cluster by running the following command:

minikube status

This will display the status of the Minikube cluster, including the IP address and state of the cluster.

Verifying the Cluster

To verify that our cluster is up and running, we can run the following command:

kubectl get nodes

This will display a list of the nodes in our cluster, which should show one node.

NAME STATUS ROLES AGE VERSION minikube Ready master 30m v1.20.0

This output confirms that we have a single-node cluster up and running, and that it’s ready for use.

Deploying an Application

Now that we have our Minikube cluster up and running, let’s deploy a simple application.

For this example, we’ll deploy a simple “Hello World” application using a Deployment. A Deployment is a Kubernetes object that manages the deployment of pods.

To deploy the application, we’ll create a Deployment definition file and use it to create the Deployment.

Here’s the definition file for our “Hello World” application:

apiVersion: apps/v1 
kind: Deployment 
metadata: 
name: hello-world 
labels: 
app: hello-world 
spec: 
replicas: 1 
selector: 
matchLabels: 
app: hello-world 
template: 
metadata: 
labels: 
app: hello-world 
spec: 
containers: 
- name: hello-world 
image: k8s.gcr.io/echoserver:1.10 
ports: 
- containerPort: 8080

This definition file creates a Deployment named “hello-world” with one replica of the “echoserver” image from the Kubernetes repository. The “echoserver” image is a simple HTTP server that returns the request headers as the response.

To create the Deployment, we’ll use the following command:

kubectl apply -f hello-world.yaml

This command will create the Deployment and the associated Pod. To check that the Pod is running, we can use the following command:

kubectl get pods

This will display a list of the pods in our cluster, including the “hello-world” pod.

NAME READY STATUS RESTARTS AGE 
hello-world-8655c9c86-2gf6b 1/1 Running 0 9m16s

With the Pod running, we can now access the “Hello World” application. To do this, we’ll create a Service to expose the Pod.

Exposing the Application

To expose the “Hello World” application, we’ll create a Service. A Service is a Kubernetes object that provides network connectivity to Pods.

Here’s the definition file for the “Hello World” Service:

apiVersion: v1 
kind: Service 
metadata: 
name: hello-world 
labels: 
app: hello-world 
spec: 
selector: 
app: hello-world 
ports:
  name: http 
  port: 80 
  targetPort: 8080 
  type: ClusterIP

This definition file creates a Service named “hello-world” that selects the “hello-world” Pod and exposes port 80, which is redirected to the container port 8080.

To create the Service, we’ll use the following command:

kubectl apply -f hello-world-service.yaml

This command will create the Service and expose the “Hello World” application. To access the application, we’ll use the following command:

minikube service hello-world --url

This command will display the URL for the “Hello World” Service. To access the application, we’ll open a web browser and navigate to the URL.

Conclusion

In this article, we’ve looked at how to create a single-node cluster with Minikube. We’ve covered the prerequisites, starting Minikube, verifying the cluster, deploying an application, and exposing the application.

Minikube is a great tool for getting started with Kubernetes and experimenting with the platform. With Minikube, you can easily create a single-node cluster and start deploying applications, making it easier to understand how Kubernetes works and how to use it to manage containers.

I hope this article has been helpful in getting you started with Minikube and Kubernetes. If you have any questions or feedback, please leave a comment.

Related Articles