Procedure

  1. Install Minikube
    • For macOS: Open the terminal and run:
      brew install minikube
    • For Windows: Install Chocolatey if not installed. Open PowerShell as Administrator and run:
      Set-ExecutionPolicy Bypass -Scope Process -Force;
      [System.Net.ServicePointManager]::SecurityProtocol =
      [System.Net.ServicePointManager]::SecurityProtocol -bor
      3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
      To check if choco is installed or not run the following command to check its version
      choco
      Then install Minikube:
      choco install minikube
    • Alternatively you can download minikube manually based on your OS:
      Alternate Method
  2. Launch Docker Desktop
    • Ensure Docker Desktop is installed and running.
    • To check Docker version run this command in terminal:
      docker version
  3. Start Minikube with Docker as the Driver
    • Run:
      minikube start --driver=docker
    • Verify Minikube status:
      minikube status
      We will see the output as:
      host: Running
      kubelet: Running
      apiserver: Running
      kubeconfig: Configured
    • Check Kubernetes cluster info:
      kubectl cluster-info
  4. Create a Deployment File
    • Create a folder named Kubernetes and a file named deployment.yaml.
    • Add the following YAML configuration:
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: my-app
      spec:
        replicas: 2
        selector:
          matchLabels:
            app: my-app
        template:
          metadata:
            labels:
              app: my-app
          spec:
            containers:
            - name: my-container
              image: nginx
              ports:
              - containerPort: 80
  5. Deploy the Application
    • Navigate to the Kubernetes folder inside the terminal.
      Mac: cd ~/Desktop/Kubernetes
      Windows: cd C:\Users\YourUsername\Desktop\Kubernetes
    • Apply the deployment:
      kubectl apply -f deployment.yaml
    • Check if deployment and pods are running:
      kubectl get deployments kubectl get pods
    • View logs of the running app:
      kubectl logs -l app=my-app
  6. Expose the Deployment
    • Expose the service as NodePort:
      kubectl expose deployment my-app --type=NodePort --port=80
    • Verify the service:
      kubectl get services
  7. Access the Application in Browser
    • Get the Minikube IP:
      minikube ip
    • Get the service URL:
      minikube service my-app --url
    • Copy & paste the URL in the browser.

This should display your Nginx welcome page or your deployed application.

Alternative Procedure

  1. Navigate to your Kubernetes Folder
  2. Open a terminal and navigate to your Kubernetes directory:
    # Mac cd ~/Desktop/Kubernetes 
    # Windows cd C:\\Users\\YourUsername\\Desktop\\Kubernetes
  3. Create index.html
  4. Use the following command to create and edit the file:
    nano index.html
    Paste the following HTML code and save the file:
    <!DOCTYPE html>
    <html lang="en">
    <head>
       <meta charset="UTF-8">
       <meta name="viewport" content="width=device-width, initial-scale=1.0">
       <title>Welcome to Nginx on Kubernetes</title>
    </head>
    <body>
       <h1>Welcome to Nginx on Kubernetes!</h1>
       <p>Deployment is successful!</p>
    </body>
    </html>
  5. Create a ConfigMap from index.html
  6. Delete any existing ConfigMap:
    kubectl delete configmap my-html-config
    Create a new ConfigMap:
    kubectl create configmap my-html-config --from-file=index.html
    Verify ConfigMap creation:
    kubectl get configmaps kubectl describe configmap my-html-config
  7. Create deployment.yaml
  8. Open the file:
    nano deployment.yaml
    Paste the following YAML configuration:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-app
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: my-app
      template:
        metadata:
          labels:
            app: my-app
        spec:
          containers:
          - name: my-container
            image: nginx
            ports:
            - containerPort: 80
            volumeMounts:
            - name: html-volume
              mountPath: /usr/share/nginx/html
          volumes:
          - name: html-volume
            configMap:
              name: my-html-config
    Save the file and apply the deployment:
    kubectl apply -f deployment.yaml
  9. Verify and expose the deployment
  10. Check running pods:
    kubectl get pods
    Verify if index.html is correctly mounted:
    kubectl exec -it <your-pod-name> -- ls -l /usr/share/nginx/html/
    Expose the deployment as a NodePort service:
    kubectl expose deployment my-app --type=NodePort --port=80
    Verify the service:
    kubectl get services
  11. Access the Application in Browser
  12. Get the Minikube IP:
    minikube ip
    Get the Service URL:
    minikube service my-app --url

Copy and paste the URL into your browser. The Nginx server will now serve your custom webpage inside Kubernetes.