Day 31 : Launching your First Kubernetes Cluster with Nginx running

Day 31 : Launching your First Kubernetes Cluster with Nginx running

DevOps Learning

We will be using Minikube to create a Kubernetes cluster. So first, let's learn about Minikube.

What Is Minikube?

Minikube is a lightweight, single-node Kubernetes cluster that you can run on your local machine. It’s like having a miniaturized Kubernetes playground right at your fingertips. Here are the key points:

  1. Local Kubernetes Environment:

    • Minikube allows developers to create and manage a simplified Kubernetes environment on their laptops or desktops.

    • It’s perfect for experimenting, testing, and learning Kubernetes features without the complexities of setting up a full-fledged cluster.

  2. Features:

    • Single Node: Minikube sets up a single-node cluster. It’s minimalistic but functional.

    • VM-Based: It creates a virtual machine (VM) using tools like VirtualBox, Hyper-V, or KVM (depending on your OS).

    • Kubectl Integration: You can use kubectl to interact with your Minikube cluster just like any other Kubernetes cluster.

    • Add-Ons: Minikube provides optional add-ons (like the Kubernetes Dashboard) that you can enable as needed.

  3. Use Cases:

    • Learning Kubernetes: If you’re new to Kubernetes, Minikube is a great starting point. You can experiment with pods, services, deployments, and more.

    • Local Development: Developers can test their applications locally before deploying them to a production cluster.

    • CI/CD Pipelines: Minikube can be part of your CI/CD pipeline for integration testing.

  4. Installation:

    • Minikube is available for Linux, macOS, and Windows systems.

    • You can install it by following the instructions on the official Minikube documentation.

After following the installation guide, you should see something like this.

Deploy application.

  1. Start Minikube if not:

    • Open your terminal and run:

        minikube start
      
    • This sets up a local Kubernetes cluster in a VM.

  2. Create a Deployment:

    • We’ll deploy a simple NGINX-based app.

    • Run:

        kubectl create deployment nginx-server --image=nginx:latest
      

  1. Expose the Deployment:

    • Expose the deployment as a service:

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

  1. Access the App:

    • Get the URL to access your app:

        minikube service nginx-server --url
      

    • Open that URL in your browser, and voilà! You’re running NGINX in your Minikube cluster.

  2. Cleanup:

    • When you’re done, stop Minikube:

        minikube stop
      

You can also deploy the application using a manifest (YAML or JSON) file.

  • Create a manifest file (deployment-nginx.yml).

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: nginx-deployment
      spec:
        selector:
          matchLabels:
            app: nginx
        replicas: 2 # tells deployment to run 2 pods matching the template
        template:
          metadata:
            labels:
              app: nginx
          spec:
            containers:
            - name: nginx
              image: nginx:latest
              ports:
              - containerPort: 80
    
  • Before Apply the YAML file to create a deployment, make sure minikube is running:

      kubectl apply -f deployment-nginx.yml
    

  • Check newly created pods, and deployment.

      kubectl get pod
      kubectl get deployment
    

  • Call the service.

       minikube service nginx-deployment
    

Thank you for reading😉.