在部署nginx(或任何应用程序)之后,我尝试使用以下配置文件公开它:
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
app: nginx
结果:
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
请注意,端口号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"}
答案 0 :(得分:7)
LoadBalancer
服务在内部使用NodePort
。是的,可以为服务指定NodePort
。有两种方法可以做到:
nodePort: 31036
进行服务。kubectl edit <service name>
,修改nodePort
下的ports
字段并保存。请注意,NodePort
必须设置为标记配置范围30000-32767
中的数字。否则,kubernetes会抛出错误。可以使用每https://kubernetes.io/docs/reference/generated/kube-apiserver/传递给NodePort
的标记--service-node-port-range
来更改此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)