0

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

King
  • 101
  • 2
  • 2

2 Answers2

2

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

Zareh Kasparian
  • 753
  • 5
  • 20
0

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/