Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

minikube service %servicename% --url return nothing

I'm trying to expose my api so I can send request to it. However when I used the command minikube service api --url I get nothing. All my pods are running fine according to kubectl get pods so I'm abit stuck about what this could be.

api-1007925651-0rt1n       1/1       Running   0          26m
auth-1671920045-0f85w      1/1       Running   0          26m
blankit-app                1/1       Running   5          5d
logging-2525807854-2gfwz   1/1       Running   0          26m
mongo-1361605738-0fdq4     1/1       Running   0          26m


jwl:.build jakewlace$ kubectl get services

NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)     AGE
api          10.0.0.194   <none>        3001/TCP    23m
auth         10.0.0.36    <none>        3100/TCP    23m
kubernetes   10.0.0.1     <none>        443/TCP     5d
logging      10.0.0.118   <none>        3200/TCP    23m
mongo        10.0.0.132   <none>        27017/TCP   23m

jwl:.build jakewlace$
jwl:.build jakewlace$ minikube service api --url
jwl:.build jakewlace$

Any help would be massively appreciated, thank you.

I realised that the question here could be perceived as being minimal, but that is because I'm not sure what more information I could show from the tutorials I've been following it should just work. If you need more information please do let me know I will let you know.

EDIT:

api-service.yml

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: api
  name: api
spec:
  ports:
  - name: "3001"
    port: 3001
    targetPort: 3001
  selector:
    io.kompose.service: api
status:
  loadBalancer: {}

api-deployment.yml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: api
  name: api
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: api
    spec:
      containers:
      - image: blankit/web:0.0.1
        name: api
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3001
        resources: {}
      restartPolicy: Always
status: {}
like image 726
Jake Lacey Avatar asked Aug 05 '17 14:08

Jake Lacey


People also ask

How do you call a service on minikube?

For eg, say your NodePort is 30080 , then your service will be accessible as 192.168. 99.100:30080 . To get the minikube ip, run the command minikube ip .

How do you get external IP address in minikube?

minikube tunnel runs as a process, creating a network route on the host to the service CIDR of the cluster using the cluster's IP address as a gateway. The tunnel command exposes the external IP directly to any program running on the host operating system. Password: Status: machine: minikube pid: 39087 route: 10.96.


1 Answers

Your configuration is fine, but only missing one thing.

There are many types of Services in Kubernetes, but in this case you should know about two of them:

ClusterIP Services:
Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster. This is the default.

NodePort:
Exposes the service on each Node’s IP at a static port (the NodePort). A ClusterIP service, to which the NodePort service will route, is automatically created. You’ll be able to contact the NodePort service, from outside the cluster, by requesting <NodeIP>:<NodePort>.

Note:
If you have a multi-node cluster and you've exposed a NodePort Service, you can access is from any other node on the same port, not necessarily the same node the pod is deployed onto.

So, getting back to your service, you should specify the service type in your spec:

kind: Service
apiVersion: v1
metadata:
  ...
spec:
  type: NodePort
  selector:
    ...
  ports:
  - protocol: TCP
    port: 3001

Now if you minikube service api --url, it should return a URL like http://<NodeIP>:<NodePort>.

Note: The default Kubernetes configuration will chose a random port from 30000-32767. But you can override that if needed.


Useful references:

  • Kubernetes / Publishing services - service types
  • Kubernetes / Connect a Front End to a Back End Using a Service
like image 101
Ayman Nedjmeddine Avatar answered Sep 30 '22 13:09

Ayman Nedjmeddine