美文网首页K8s
一文学会k8s端口调整

一文学会k8s端口调整

作者: sknfie | 来源:发表于2022-06-02 23:22 被阅读0次

    概述

    通过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容器是否已重启,如果没有自动重启,需手工重启

    相关文章

      网友评论

        本文标题:一文学会k8s端口调整

        本文链接:https://www.haomeiwen.com/subject/hfjcmrtx.html