Minikube service% servicename% --url returns nothing
I am trying to expose my api to send a request. However, when I used the command minikube service api --url
, I got nothing. All my pods are working fine according to kubectl get pods
, so I don't get hung up on what it might 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 greatly appreciated, thanks.
I realized that the question here can be taken as a minimal one, but that is because I'm not sure if more information I could show from the tutorials I follow should just work. If you need more information, please 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: {}
source to share
Your configuration is fine, but only one thing is missing.
There are many types of Services in Kubernetes , but in this case, you should be aware of two of them:
ClusterIP Services:
Provides a service on an internal IP cluster. Selecting this value makes the service available only within the cluster. This is the default.NodePort:
Provides service on each Node IP address on a static port (NodePort). The ClusterIP service to which the NodePort service will be directed is automatically created. You can contact the NodePort service from outside the cluster by requesting<NodeIP>:<NodePort>
.
Note:
If you have a multi-node cluster and have opened a NodePort service, you can access from any other node on the same port, not necessarily the same node that hosts the module.
So, going back to your service, you must specify the service type in your specification:
kind: Service
apiVersion: v1
metadata:
...
spec:
type: NodePort
selector:
...
ports:
- protocol: TCP
port: 3001
Now if you are minikube service api --url
, it should return a url eg http://<NodeIP>:<NodePort>
.
Note. ... Kubernetes config by default picks a random port from 30000-32767. But you can override this if needed.
Useful links:
source to share