概述
通過node port方式暴露的服務(wù),kubernetes集群默認(rèn)端口范圍為30000-32767,但是可以通過手工修改。
實戰(zhàn)
1、部署nginx服務(wù)
- nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
name: nginx-test
name: nginx-test
namespace: default
spec:
replicas: 1
selector:
matchLabels:
name: nginx-test
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
name: nginx-test
spec:
containers:
- image: registry.yunlearn.org:5000/release/nginx:1.19.6
imagePullPolicy: IfNotPresent
name: nginx-test
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
nginx-svc.yaml
apiVersion: v1
kind: Service
metadata:
labels:
name: nginx-test
name: nginx-test
namespace: default
spec:
ports:
- name: http
nodePort: 8088
port: 80
protocol: TCP
targetPort: 80
selector:
name: nginx-test
type: NodePort
發(fā)現(xiàn)錯誤并處理
- 部署
kubectl create -f nginx-deploy.yaml
kubectl create -f nginx-svc.yaml
The Service "nginx" is invalid: spec.ports[0].nodePort: Invalid value: 80: provided port is not in the valid range. The range of valid ports is 30000-32767
- 修改配置
kubernetes集群默認(rèn)端口范圍為30000-32767,企業(yè)可根據(jù)需求修改合適的端口范圍
vi /etc/kubernetes/manifests/kube-apiserver.yaml
//找到 - --service-cluster-ip-range這一行,在這一行的下一行增加一行內(nèi)容
- --service- node-port-range=10-65000
實操提示:三個master都需要修改,并檢查apiserver容器是否已重啟,如果沒有自動重啟,需手工重啟