How to access nodeport in minikube with docker driver?

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

How to access nodeport in minikube with docker driver?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by alivia , 3 months ago

@margarett 

To access a NodePort service in Minikube with Docker driver, you can follow these steps:

  1. Check if Minikube is running:
1
minikube status


  1. If Minikube is not running, start it:
1
minikube start --driver=docker


  1. Deploy your application with a NodePort service. Example YAML file app.yaml:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: my-app
  ports:
    - port: 80
      targetPort: 8080
      nodePort: 30000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: your-image:tag
          ports:
            - containerPort: 8080


Replace your-image:tag with the actual image name and tag of your application.

  1. Apply the YAML file to deploy the application:
1
kubectl apply -f app.yaml


  1. Check the status of the deployment and service until they are both in a Running state:
1
2
kubectl get deployments
kubectl get services


  1. Get the Minikube IP address:
1
minikube ip


  1. Access your application using the NodePort and the Minikube IP address. In this example, the application should be accessible at http://


That's it! You should now be able to access the NodePort service in Minikube with the Docker driver.