Score:0

Connecting NodePort in Minikube

cn flag

I created a Service and a Deployment but I am unable to access the service with minikube service --url accounts-service or minikube service accounts-service.

While the second one opens the browser but never connects, the first one just remains in my terminal.

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: accounts-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: accounts-service
  template:
    metadata:
      labels:
        app: accounts-service
    spec:
      containers:
        - name: accounts-service
          image: xxxx:latest
          ports:
            - containerPort: 3001

Service

apiVersion: v1
kind: Service
metadata:
  name: accounts-service
spec:
  selector:
    app: accounts-service
  ports:
    - port: 80
      targetPort: 3001
  type: NodePort

I don't know why my Minikube is not connecting to the Port. I am using minkube with Docker

asktyagi avatar
in flag
Can you post kubectl get output for deploy and service as well? Also where you defined nodePort?
Score:1
us flag

King, you have defined targetPort to 3001, this connects this service to your pod, but you haven't defined nodePort. NodePort is the port number to call the service on that port externally. so if you want get to the service you need to run (for minikube maybe its something different but the same result)

kubectl get svc

so in your case, the port which you have to look for is X:PORTNUMBER. 30891 in my cluster is been chosen.Although you may choose the port number manually as well via nodePort definition in your yaml file. enter image description here

by this you will see the port number which is automatically selected by kubeproxy. for a better understanding of the port concepts, I will share the following image.

enter image description here

Score:0
eg flag

If you are using minikube in Windows with the docker driver this is "normal", although as previously mentioned you are missing the nodePort defined in your yaml. A good way to access your service is to port-forward your service.

kubectl port-forward service {serviceName} -n {namespaceName} {portNumberToAccess}:{portNumberOfService}

And then access it with your browser by using your Node ip adress and the port.

(you can check your node ip adress by using minikube ip )

Example: http://{NodeIpAdress}:{portNumberToAccess}

More info here: https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.