• service几种访问类型(集群外负载均衡访问LoadBalancer , 集群内访问ClusterIP,集群内访问headless ClusterIP,VPC内网负载均衡LoadBalancer ,集群外访问NodePort)


    一、集群外访问(负载均衡)

    kind: Service
    apiVersion: v1
    spec:
      ports:
        - protocol: TCP
          port: 4341
          targetPort: 8080
          nodePort: 30875
      type: LoadBalancer
      externalIPs: #外部负载均衡
        - 172.30.10.4
        - 172.30.10.3
      sessionAffinity: None
      externalTrafficPolicy: Cluster

    二、k8s集群内访问

    # clusterip service

    kind: Service
    apiVersion: v1
    spec:
          clusterIP: 10.43.22.26 (如果不填,会自动添加)
      ports:
        - protocol: TCP
          port: 4321
          targetPort: 8080
      type: ClusterIP
      externalIPs: #集群内互访 可选
        - 172.30.10.201
         - 172.30.10.42

    # headless service

    spec:
      clusterIP: None
      ports:
      - name: tcp-postgresql
        port: 5432
        protocol: TCP
        targetPort: tcp-postgresql
      selector:
        app: postgresql
      type: ClusterIP

    三、vpc内网负载均衡

    kind: Service
    apiVersion: v1
    metadata:
    annotations:
      kubernetes.io/elb.class: elasticity #表示选择的是经典负载均衡实例
      kubernetes.io/elb.vpc.id: 0e86e303-7a82-4e03-a435-9be0c4771c93 #负载均衡所在vpc的ID
    spec:
      ports:
      - name: cce-service-0
           protocol: TCP
           port: 4321
           targetPort: 8080
           nodePort: 31118
      type: LoadBalancer
      loadBalancerIP: 172.30.12.33
      sessionAffinity: None
      externalTrafficPolicy: Cluster

    四、集群外访问,NodePort

    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: prometheus-operator-operator
      name: my-release-prometheus-oper-operator
      namespace: default
    spec:
      ports:
      - name: http
        port: 8080
        protocol: TCP
        targetPort: http
        nodePort: 30080
      selector:
        app: prometheus-operator-operator
      sessionAffinity: None
      type: NodePort

     #clusterIP: None 这里不能设置为空,因为nodeport需要映射到clusterip ,因此这里要么不设置clusterIP,要么手动配ip

  • 相关阅读:
    你不会Python这几个库,不要说你会爬虫
    如何用Python破解验证码,适合新手练手
    2020最新Python入门笔记
    10个超有趣的Python项目,你会哪个?
    Python编程必学规范【新手必学】
    你对Python变量理解到位了没有,80%的人都不知道
    这个男人让你的python爬虫开发效率提升8倍
    Python抖音机器人,论如何在抖音上找到漂亮小姐姐?
    在Python中实现函数重载,60%的人都不会
    2020十大Python面试题,你会几个?
  • 原文地址:https://www.cnblogs.com/kevincaptain/p/9929717.html
Copyright © 2020-2023  润新知