Day 31: Deploying Your First Kubernetes Cluster with Nginx

Day 31: Deploying Your First Kubernetes Cluster with Nginx

ยท

3 min read

Awesome! You learned the architecture of one of the most important tools "Kubernetes" in your previous task.

What about some hands-on now?

Let's read about minikube and implement k8s in our local machine

What is minikube?

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

Minikube is a pared-down version of Kubernetes that gives you all the benefits of Kubernetes with a lot less effort.

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

There are numerous features of Minikube but here are some common features:

  • Supports the latest Kubernetes release (+6 previous minor versions)

  • Cross-platform (Linux, macOS, Windows)

  • Deploy as a VM, a container, or on bare-metal

  • Multiple container runtimes (CRI-O, containers, docker)

  • Direct API endpoint for blazing-fast image load and build

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

  • Addons for easily installed Kubernetes applications

  • Supports common CI environments

Installation of minikube

To install the minikube on your local system, click here minikube installation <-

Simply select the OS where you want to install the minikube, copy the commands and paste it on your local to install the minikube.

What is Pod?

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.

A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers. A Pod's contents are always co-located and co-scheduled, and run in a shared context. A Pod models an application-specific "logical host": it contains one or more application containers which are relatively tightly coupled.

Task

Create your first pod on Kubernetes through minikube

Steps:

  • If you haven't installed the minikube in your local system yet, install it by going through the link mentioned above in the Installation of minikube section.

  • Open your terminal or command prompt and start Minikube by running the following command:

      minikube start
    
  • Create a YAML file that defines your pod. e.g. my-pod.yml. Enter the following content in it:

      apiVersion: v1
      kind: Pod
      metadata: 
        name: my-pod
      spec:
        containers:
           - name: my-container
             image: nginx
             ports:
               - containersPort: 80
    

    This YAML file defines a basic pod named "my-pod" that runs an Nginx container.

  • Apply the pod manifest to your Minikube cluster by running the following command:

      kubectl apply -f my-pod.yml
    

    This command deploys the pods on the configuration in the YAML file.

  • To verify your pod is running, run the following command:

      kubectl get pods
    

    It displays the list for your pod and its status whether it's running or not.

  • Now you can access the Nginx web server running in your pod by opening a web browser and navigating to localhost:80

Congratulations, you've created your first pod on Kubernetes with Minikube. Practice it to make it perfect for your understanding.


<That's all for today. Hope you like it. FOLLOW to join me in the journey of DevOps>

ย