Effortless Kubernetes Cluster Launch with Nginx: A Quick Guide | Day 31 of 90 Days of DevOps

Ajit Fawade
5 min readSep 12, 2023

--

Welcome to Day 31 of 90 Days of DevOps. In this blog post, I will show you how to launch a Kubernetes cluster with Nginx using minikube on AWS EC2 machines.

What is minikube?

Minikube is a tool that lets you run Kubernetes locally on a single node. It creates a virtual machine (VM) and installs a Kubernetes cluster inside it. You can use minikube to learn and experiment with Kubernetes without needing a lot of resources or a cloud provider.

Some of the benefits of minikube are:

  • It is easy to install and use.
  • It supports most of the Kubernetes features and add-ons.
  • It is compatible with various operating systems and hypervisors.
  • It allows you to switch between different Kubernetes versions and configurations.

How to install minikube on AWS EC2 machines?

To install minikube on AWS EC2 machines, you need to follow these steps:

1. Launch an EC2 instance with Ubuntu 22.04 image and at least 2 CPUs or more, 2GB of free memory, and 20GB of free disk space. You can use any instance type that meets these requirements, such as t2.medium which does not come under the free tier.

2. Connect to the instance via SSH and update the packages with the command:

sudo apt update && sudo apt upgrade -y

3. Install Docker, which is the container runtime that minikube uses by default. You can use the official script from Docker to install it with the command:

sudo apt install docker.io

4. Add your user to the docker group so that you can run docker commands without sudo. You need to log out and log in again for this change to take effect. You can do this with the command:

sudo usermod -aG docker $USER

5. Install kubectl, which is the command-line tool for interacting with Kubernetes clusters.

sudo snap install kubectl --classic

6. Install minikube, which is the main tool for creating and managing local Kubernetes clusters. You can download the latest version from the GitHub releases page and make it executable with the commands:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 

sudo install minikube-linux-amd64 /usr/local/bin/minikube

7. Start minikube with the command:

minikube start

This will create a VM and install a Kubernetes cluster inside it. It may take a few minutes to complete.

Verify that minikube is running and that you can connect to the cluster with kubectl with the command:

minikube status && kubectl get nodes

You should see something like this:

Congratulations! You have successfully installed minikube on AWS EC2 machines and launched a local Kubernetes cluster.

What is a pod?

A pod is the basic unit of deployment in Kubernetes. It is a group of one or more containers that share the same network and storage resources. A pod can run a single application or a part of an application.

Some of the characteristics of pods are:

  1. They are ephemeral, meaning they can be created and destroyed at any time.
  2. They are assigned a unique IP address within the cluster, which allows them to communicate with other pods and services.
  3. They can mount volumes for persistent data storage or configuration files.
  4. They can have labels and annotations for identification and metadata purposes.

They can have health checks and lifecycle hooks for monitoring and management.

How to create a pod on Kubernetes using minikube?

To create a pod on Kubernetes using minikube, you need to follow these steps:

  1. Create a YAML file that defines the pod specification. For example, you can create a file named nginx-pod.yaml with the following content:
apiVersion: v1
kind: Pod
metadata:
name: nginx
label:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

This file defines a pod named nginx with the label name=nginx. It has one container named nginx that uses the nginx image from Docker Hub and exposes port 80.

2. Apply the YAML file to the cluster with the command:

kubectl apply -f my-pod.yaml

3. This will create the pod and pull the image from Docker Hub if it is not already cached.

4. Check the status of the pod with the command:

kubectl get pod nginx

5. You should see something like this:

This means that the pod is running and ready.

6. To access the NGINX web server running in your Pod, you need to expose it as a service. You can use the following command to create a NodePort service:

kubectl expose pod nginx --type=NodePort --port=80

7. Access the pod from your browser by using the minikube service command, which creates a temporary URL for the pod. You can do this with the command:

minikube service nginx --url

8. Copy and paste this URL into your browser and you should see the default Nginx welcome page.

Congratulations! You have successfully created your first pod on Kubernetes using minikube.

Summary

In this blog post, I have shown you how to launch a Kubernetes cluster with Nginx using minikube on AWS EC2 machines. You have learned what is minikube, how to install it, what is a pod, and how to create one.

I hope you found this post useful and informative.

If you want to learn more about DevOps, you can follow me on GitHub and LinkedIn, where I share my projects and articles.

GitHub: https://github.com/ajitfawade

LinkedIn: https://www.linkedin.com/in/ajitfawade/

--

--

No responses yet