Procedure
- 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:
To check if choco is installed or not run the following command to check its versionSet-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'))
choco
Then install Minikube:choco install minikube - Alternatively you can download minikube manually based on your OS:
Alternate Method
- For macOS: Open the terminal and run:
- Launch Docker Desktop
- Ensure Docker Desktop is installed and running.
- To check Docker version run this command in terminal:
docker version
- Start Minikube with Docker as the Driver
- Run:
minikube start --driver=docker - Verify Minikube status:
We will see the output as:minikube status
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured - Check Kubernetes cluster info:
kubectl cluster-info
- Run:
- Create a Deployment File
- Create a folder named
Kubernetesand a file nameddeployment.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
- Create a folder named
- Deploy the Application
- Navigate to the
Kubernetesfolder 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
- Navigate to the
- Expose the Deployment
- Expose the service as NodePort:
kubectl expose deployment my-app --type=NodePort --port=80 - Verify the service:
kubectl get services
- Expose the service as NodePort:
- 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.
- Get the Minikube IP:
This should display your Nginx welcome page or your deployed application.
Alternative Procedure
- Navigate to your Kubernetes Folder Open a terminal and navigate to your Kubernetes directory:
- Create index.html Use the following command to create and edit the file:
- Create a ConfigMap from index.html Delete any existing ConfigMap:
- Create deployment.yaml Open the file:
- Verify and expose the deployment Check running pods:
- Access the Application in Browser Get the Minikube IP:
# Mac cd ~/Desktop/Kubernetes
# Windows cd C:\\Users\\YourUsername\\Desktop\\Kubernetesnano index.htmlPaste 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>kubectl delete configmap my-html-configCreate a new ConfigMap:kubectl create configmap my-html-config --from-file=index.htmlVerify ConfigMap creation:kubectl get configmaps kubectl describe configmap my-html-confignano deployment.yamlPaste 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-configSave the file and apply the deployment:kubectl apply -f deployment.yamlkubectl get podsVerify 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=80Verify the service:kubectl get servicesminikube ipGet the Service URL:minikube service my-app --urlCopy and paste the URL into your browser. The Nginx server will now serve your custom webpage inside Kubernetes.