minikube expose service on specific port

大城市里の小女人 提交于 2019-12-11 06:55:32

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/53272296/minikube-expose-service-on-specific-port

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!