Minikube公开了loadbalancer类型的随机端口.我可以定义特定端口吗?

thi*_*bot 3 kubernetes minikube

在部署nginx(或任何应用程序)之后,我尝试使用以下配置文件公开它:

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 80
  selector:
    app: nginx
Run Code Online (Sandbox Code Playgroud)

结果:

C:\install\kube>kubectl get service -l app=nginx
NAME      TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
nginx     LoadBalancer   10.108.193.215   <pending>     80:31035/TCP   21h
Run Code Online (Sandbox Code Playgroud)

请注意,端口号31035是随机分配的.是否可以定义特定端口?

版本:

C:\install\kube>minikube version
minikube version: v0.24.1

C:\install\kube>kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0", GitCommit:"6e937839ac04a38cac63e6a7a306c5d035fe7b0a", GitTreeState:"clean", BuildDate:"2017-09-28T22:57:57Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0", GitCommit:"0b9efaeb34a2fc51ff8e4d34ad9bc6375459c4a4", GitTreeState:"clean", BuildDate:"2017-11-29T22:43:34Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"linux/amd64"}
Run Code Online (Sandbox Code Playgroud)

Vik*_*ote 7

LoadBalancer服务在NodePort内部使用.是的,可以指定NodePort服务.有两种方法可以做到:

  1. 使用nodePort: 31036在YAML spec文件的服务.
  2. 运行kubectl edit <service name>,编辑下面的nodePort字段ports并保存.

请记住,NodePort必须将其设置为标志配置范围范围内的数字30000-32767.否则,kubernetes会抛出错误.这个NodePort范围可以使用标志更改--service-node-port-range传递给kube-apiserverhttps://kubernetes.io/docs/reference/generated/kube-apiserver/:

  --service-node-port-range portRange      A port range to reserve for services
                                           with NodePort visibility. 
                                           Example: '30000-32767'. Inclusive at both ends
                                           of the range. (default 30000-32767)
Run Code Online (Sandbox Code Playgroud)