# How to setup Kubernetes Cluster using Minikube

Kubernetes is an open-source platform for automating deployment, scaling, and management of containerized applications. Minikube is a tool that makes it easy to run a single-node Kubernetes cluster locally, for development and testing purposes. In this article, we will walk you through the steps to set up a Kubernetes cluster using Minikube on your local machine.

Step 1: Install Minikube

To set up a Kubernetes cluster using Minikube, you first need to install Minikube on your local machine. The process of installing Minikube depends on your operating system. Minikube is available for Windows, macOS, and Linux.

Here are the installation steps for macOS and Linux:

1. Install a hypervisor: Minikube requires a hypervisor to run virtual machines on your local machine. The most commonly used hypervisors are VirtualBox and HyperKit. In this article, we will use VirtualBox.
    
2. Install kubectl: kubectl is the Kubernetes command-line tool that you will use to manage your Minikube cluster. You can install kubectl using the following command:
    
    ```bash
    curl -LO https://dl.k8s.io/release/stable.txt && sudo mv stable.txt /usr/local/bin/kubectl && sudo chmod +x /usr/local/bin/kubectl
    ```
    
3. Install Minikube: Minikube can be installed using a package manager such as Homebrew or by downloading a pre-compiled binary from the Minikube website. To install Minikube using Homebrew, run the following command:
    
    ```bash
    brew install minikube
    ```
    

Step 2: Start Minikube

Once Minikube is installed, you can start a Minikube cluster using the following command:

```bash
minikube start
```

This command will create a single-node Kubernetes cluster using VirtualBox and configure kubectl to use it.

Step 3: Verify the Minikube cluster

To verify that the Minikube cluster is running, you can use the following command:

```bash
kubectl get nodes
```

This command will display information about the nodes in your Minikube cluster. You should see a single node named `minikube` with the status `Ready`.

Step 4: Deploy a sample application

Now that you have a Minikube cluster running, you can deploy a sample application to test it. In this example, we will deploy a simple web server using a Kubernetes deployment.

To create a deployment, you need to define a YAML file that specifies the desired state of the application. Here is an example YAML file for a simple web server:

```yaml
yamlCopy codeapiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
replicas: 3
selector:
  matchLabels:
    app: nginx
template:
  metadata:
    labels:
      app: nginx
  spec:
    containers:
    - name: nginx
      image: nginx:1.15
      ports:
      - containerPort: 80
```

To create the deployment, run the following command:

```bash
kubectl apply -f <filename>.yaml
```

where `<filename>` is the name of the YAML file you created in the previous step.

Once the deployment is created, you can verify that the pods are running by using the following command:

```bash
kubectl get pods
```

You should see three pods, each running an instance of the nginx web server.

Step 5: Expose the application

Now that the pods are running, you need to expose them so that you can access the web server from your local machine. You can expose a Kubernetes service using a YAML file, just like you created a deployment. Here is an example YAML file for exposing the nginx service:

```yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - name: http
    port: 80
    targetPort: 80
  type: NodePort
```

To create the service, run the following command:

```bash
kubectl apply -f <filename>.yaml
```

where `<filename>` is the name of the YAML file you created in the previous step.

Once the service is created, you can access the web server by using the URL `http://<minikube-ip>:<node-port>`, where `<minikube-ip>` is the IP address of the Minikube virtual machine and `<node-port>` is the node port assigned to the service. You can find the Minikube IP and node port by using the following command:

```bash
minikube service nginx-service --url
```

That's it! You have now set up a single-node Kubernetes cluster using Minikube and deployed a sample application to it. You can now experiment with different Kubernetes objects, such as pods, services, and deployments, to learn more about how Kubernetes works.

In conclusion, Minikube is a great tool for learning and experimenting with Kubernetes without the need for a full-fledged cluster. By following these steps, you can quickly set up a single-node Kubernetes cluster on your local machine and start exploring the world of containers and container orchestration.
