Minikube NGINX Setup: Deploying and Exposing NGINX on Kubernetes
This guide will walk you through running an NGINX app on a Minikube cluster. Follow the instructions below to set up the necessary Kubernetes configurations and deploy your NGINX app.
- Minikube installed and running
- kubectl installed
- Basic knowledge of Kubernetes and YAML configuration files
First, start your Minikube cluster. This command will initiate a local Kubernetes cluster using Minikube.
minikube startCreate a new directory for your project and navigate into it.
mkdir Project
cd ./Project/Now, create a deployment.yaml file using the following command. You will edit this file to define the Kubernetes Deployment for NGINX.
New-Item deployment.yml
New-Item deployment.yaml
rm ./deployment.yml
notepad deployment.yamlEdit the deployment.yaml file to define the NGINX deployment. Example content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80Once the deployment.yaml file is ready, apply the deployment configuration to the Minikube cluster.
kubectl apply -f deployment.yamlNext, create a service.yaml file to expose your NGINX app as a service.
New-Item service.yaml
notepad service.yamlEdit the service.yaml file with the following content:
apiVersion: v1
kind: Service
metadata:
name: access-app-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: NodePortAfter editing the service.yaml file, apply the service configuration.
kubectl apply -f service.yamlCheck the nodes and services to ensure that the deployment and service are running.
kubectl get nodes
kubectl get serviceskubectl expose deployment access-app-deployment \
--name=access-app-service \
--type=LoadBalancer \
--port=80 \
--target-port=80
To access your NGINX app, use the following command to open the service in your default browser.
minikube service access-app-serviceThis will expose your NGINX app on a Minikube local IP.
Now you have successfully deployed an NGINX application on Minikube and exposed it through a Kubernetes service. You can modify the deployment and service configurations as needed.
For more information, check the Minikube documentation and the Kubernetes documentation.