minikube

3 min read

Cover Image for minikube

miniKube

  1. What is minikube?

  2. minikube is a tool that quickly sets up a local Kubernetes cluster on macOS, Linux, and Windows. It can deploy as a VM, a container, or on bare metal.

  3. To be precise, it is a one-node Cluster that runs on a virtual box used for testing purposes.

  4. minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes.

  5. This makes it an interesting option for users who are new to containers, and also for projects in the world of edge computing and the Internet of Things.

    Features of minikube

    1. Cross-platform (Linux, macOS, Windows)

    2. Deploy as a VM, a container, or on bare-metal

    3. Multiple container runtimes (CRI-O, containers, docker)

    4. Direct API endpoint for blazing-fast image load and build

    5. Advanced features such as LoadBalancer, filesystem mounts, FeatureGates, and network policy

    6. Addons for easily installed Kubernetes applications

    7. Supports common CI environments

Task1: Installation of Minikube

  1. make sure docker is installed in your local environment.

    you can install it with this command

     sudo apt install docker.io
    
     //start docker
     sudo systemctl start docker
    

    you can verify by running the command

     sudo systemctl status docker
    
  2. Now download minikube binary(for ubuntu 22.04 (it x86-64 architecture) file from the official Kubernetes site: https://minikube.sigs.k8s.io/docs/start/

  3. Now run the following command to install minikube

     curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
     sudo install minikube-linux-amd64 /usr/local/bin/minikube
    
  4. now start minikube with this command

     minikube start
    

    it will show on the terminal like this:

minikube comes with kubectl in-build installed which helps us to interact with the containers running on minikube.

minikube CLI -> used to start/delete the cluster

kubectl CLI -> used to configure the minikube cluster

Task2: Launching a nginx pod on minikube

  1. Start by ensuring that Minikube is running. Open a terminal or command prompt and start Minikube by running the following command: minikube start

  2. Once Minikube is running, you can create an nginx pod using a YAML manifest. Create a file called nginx-pod.yaml and open it in a text editor. Paste the following YAML configuration into the file:

  3. Kubernetes will create the pod based on the manifest. You can check the status of the pod by running:

     kubectl get pods
    

    You should see the nginx-pod list with a status of "Running".

  4. To access the nginx service running inside the pod, you need to expose the pod as a service. You can use the following command:

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

    #NOTE

    here, an error can be shown if the nginx-pod is not labeled.

    make sure under the metadata add a labels section with the app: nginx.

     apiVersion: v1
     kind: Pod
     metadata:
       name: nginx-pod
       labels:
         app: nginx
     spec:
       containers:
         - name: nginx
           image: nginx
           ports:
             - containerPort: 80
    
  5. To get the URL to access the nginx service, run the following command:

     minikube service nginx-pod --url
    

congratulation!!💜we have created an Nginx pod in minikube.

Happy learning!