Home » Backend Dev » kubernetes » 30 Days kubernetes » Day 4: Kubernetes – Setting Up Kubernetes

Day 4: Kubernetes – Setting Up Kubernetes

Introduction to Setting Up Kubernetes

Kubernetes is a powerful tool for managing containerized applications, but before you can use it, you need to set up your Kubernetes cluster. Whether you prefer a local setup for learning or a cloud-based solution for production, this guide provides a step-by-step approach to getting started with Kubernetes.

In this article, we will explore different installation options and guide you through setting up Kubernetes locally using Minikube.


Options for Installing Kubernetes

Kubernetes offers flexibility in how it can be installed. Depending on your goals and environment, you can choose from several options:

1. Minikube

Minikube is a local Kubernetes implementation designed for development and testing. It runs a single-node cluster on your machine.

2. Kind (Kubernetes in Docker)

Kind uses Docker containers to simulate Kubernetes clusters. It’s lightweight and ideal for CI/CD pipelines.

3. Managed Kubernetes Services

Cloud providers offer managed Kubernetes services like:

  • Google Kubernetes Engine (GKE)
  • Amazon Elastic Kubernetes Service (EKS)
  • Azure Kubernetes Service (AKS)

4. Kubernetes on Virtual Machines

Tools like kubeadm allow you to set up Kubernetes on virtual machines, providing more control over the configuration.


Step-by-Step Guide: Installing Kubernetes Locally Using Minikube

Prerequisites

Before you begin, ensure the following:

  1. Hardware Requirements:
    • 2 CPUs or more
    • 2GB of free memory
    • 20GB of free disk space
  2. Software Requirements:
    • A hypervisor (e.g., VirtualBox, Hyper-V, or KVM)
    • Command-line tools: kubectl and Minikube

Installing Minikube

Step 1: Install Minikube

On Linux:

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

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

On macOS:

brew install minikube

On Windows:

Download the Minikube installer from the official Minikube website.

Step 2: Start Minikube

minikube start

This command creates and starts a single-node Kubernetes cluster.

Step 3: Verify the Installation

kubectl get nodes

You should see a single node named minikube in the output.

Using Kubernetes with Minikube

Now that your cluster is up and running, let’s deploy a simple application.

Step 1: Create a Deployment

Use the following YAML file to deploy a sample Nginx application:

apiVersion: apps/v1

kind: Deployment

metadata:

name: nginx-deployment

labels:

app: nginx

spec:

replicas: 2

selector:

matchLabels:

app: nginx

template:

metadata:

labels:

app: nginx

spec:

containers:

-name: nginx

image: nginx:1.14.2

ports:

-containerPort: 80

Save this file as nginx-deployment.yaml and apply it:

kubectl apply -f nginx-deployment.yaml

Step 2: Expose the Deployment

Expose the application using a service:

kubectl expose deployment nginx-deployment –type=NodePort –port=80

Step 3: Access the Application

Get the URL to access the application:

minikube service nginx-deployment –url

Open the provided URL in your browser to see the Nginx welcome page.


Benefits of Using Minikube for Local Development

  1. Simple Setup: Minikube simplifies the process of running Kubernetes locally.
  2. Cost-Effective: No need for cloud resources; everything runs on your local machine.
  3. Experimentation-Friendly: Easily create and destroy clusters for testing purposes.

Troubleshooting Tips

  1. Minikube Fails to Start:
    • Ensure that your hypervisor is installed and running.
    • Check logs using minikube logs.
  2. kubectl Not Found:
    • Install kubectl using the instructions here.
  3. Application Not Accessible:
    • Verify that the service is exposed correctly.
    • Use kubectl describe service <service-name> to debug.

Conclusion

Setting up Kubernetes is the first step toward managing containerized applications effectively. With Minikube, you can quickly create a local Kubernetes environment to experiment, learn, and build your skills. As you progress, consider exploring other installation options like managed Kubernetes services for production use.


References

*** Your support will help me continue to bring new Content. Love Coding *** ❤️


Feedback and Discussion

Have questions or feedback? Comment below! Let’s build a collaborative learning environment. Check out more articles on Node.js, Express.js, and System Design.

Leave a Comment

Your email address will not be published. Required fields are marked *