How to expose nginx in minikube to outside?

Member

by lonzo , in category: General Help , 3 months ago

How to expose nginx in minikube to outside?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by gaston , 3 months ago

@lonzo 

To expose Nginx in Minikube to the outside, you need to follow these steps:

  1. Start Minikube by running the command: minikube start
  2. Create a Nginx deployment by applying the following YAML configuration:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80


Save the above configuration in a file called nginx-deployment.yaml and apply it using the command: kubectl apply -f nginx-deployment.yaml

  1. Expose the Nginx deployment by creating a service. Create a file called nginx-service.yaml with the following content:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP


Apply the service using the command: kubectl apply -f nginx-service.yaml

  1. Get the NodePort of the Nginx service by running: kubectl get service nginx-service
  2. Access the Nginx service from outside the Minikube cluster by using the IP of Minikube and the NodePort obtained in the previous step. The URL format will be:


By following these steps, you should be able to expose Nginx running in Minikube to the outside.