Is it possible to expose a service on a specific port using minikube
?
kubectl expose deployment my-deployment --type=NodePort --port=80
does not throw an error but when calling
minikube service my-deployment --url
it results in something like:
http://192.168.99.100:31512
and it is not available on port 80
but on port 31512
instead.
Using minikube service with tunnel Services of type NodePort can be exposed via the minikube service <service-name> --url command. It must be run in a separate terminal window to keep the tunnel open. Ctrl-C in the terminal can be used to terminate the process at which time the network routes will be cleaned up.
Now you can use minikube to retrieve a URL that is accessible outside of the container. This URL will allow you to access the hello-app service that is running on port 8080 inside your cluster.
minikube service help Simply type service help [path to command] for full details.
Ways to connect You have several options for connecting to nodes, pods and services from outside the cluster: Access services through public IPs. Use a service with type NodePort or LoadBalancer to make the service reachable outside the cluster. See the services and kubectl expose documentation.
Valid ports for minikube
of type nodePort
by default are 30000-32767
according to https://kubernetes.io/docs/concepts/services-networking/service/#nodeport
I was able to specify a particular port (here: 30000
in that range using this services.yaml
:
apiVersion: v1
kind: Service
metadata:
name: my-deployment
labels:
app: my-deployment
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30000
protocol: TCP
selector:
app: my-deployment
When starting minikube
this way:
minikube start --extra-config=apiserver.service-node-port-range=80-30000
, port 80
can be used as well:
apiVersion: v1
kind: Service
metadata:
name: my-deployment
labels:
app: my-deployment
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 80
protocol: TCP
selector:
app: my-deployment
minikube service my-deployment --url
now returns http://192.168.99.100:80
as expected and the application is available on port 80
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With