I am new to kubernate and minikube , I am trying to use service of type NodePort to be able to access the pods from host machine browser, the issue that minikube ignores the specified port in the service yaml file and instead minikube exposes a new port number randomly.
here is my configuration
apiVersion: v1
kind: Service
metadata:
name: test
spec:
type: NodePort
selector:
app: test
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30036 ==> here is port
as you can see the specified port is 30036, and that what I get when describe the service
kubectl describe services test
-----------------------------------
Name: test
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=test
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.104.58.44
IPs: 10.104.58.44
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30036/TCP
Endpoints: 192.168.50.2:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
but when try to run minikube service --url, I am getting a different port number which I think it is randomly generated
minikube service test --url
------------------------------
* Starting tunnel for service test.
|-----------|------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------|-------------|------------------------|
| default | test | | http://127.0.0.1:56758 |
|-----------|------------|-------------|------------------------|
http://127.0.0.1:56758
and here is the output of
kubectl get svc -A
-------------------------
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default test NodePort 10.104.58.44 <none> 80:30036/TCP 4h4m
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d1h
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 3d1h
so how can I make minikube use the specified port "30036" instead of generating new random one.