概述
通过node port方式暴露的服务,kubernetes集群默认端口范围为30000-32767,但是可以通过手工修改。
实战
1、部署nginx服务
- 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
发现错误并处理
- 部署
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集群默认端口范围为30000-32767,企业可根据需求修改合适的端口范围
vi /etc/kubernetes/manifests/kube-apiserver.yaml
//找到 - --service-cluster-ip-range这一行,在这一行的下一行增加一行内容
- --service- node-port-range=10-65000
实操提示:三个master都需要修改,并检查apiserver容器是否已重启,如果没有自动重启,需手工重启
网友评论