云容器引擎 CCE-负载均衡(LoadBalancer):Service使用HTTP

时间:2023-11-01 16:25:54

Service使用HTTP

Service使用HTTP仅1.21及以上版本集群支持。

Service支持使用ELB的7层能力,共享型和独享型ELB都支持对接。独享型ELB实例有如下限制:

  • 对接已有的独享型ELB实例,需要独享型ELB实例同时支持4层和7层的flavor,否则会功能不可用。
  • 使用自动创建的ELB实例,注意同时使用独享型ELB实例的4层和7层能力,需要在kubernetes.io/elb.autocreate的annotation中指定4层和7层flavor。

使用ELB的7层能力时,需要添加如下annotation:

  • kubernetes.io/elb.protocol-port: "https:443,http:80"

    protocol-port的取值需要和service的spec.ports字段中的端口对应,格式为protocol:port,port中的端口会匹配service.spec.ports中端口,并将该端口发布成对应的protocol协议。

  • kubernetes.io/elb.cert-id: "17e3b4f4bc40471c86741dc3aa211379"

    cert-id内容为ELB证书管理的证书ID,当protocol-port指定了https协议,ELB监听器的证书会设置为cert-id证书,当发布多个HTTPS的服务,会使用同一份证书。

配置示例如下,其中spec.ports中两个端口与kubernetes.io/elb.protocol-port中对应,443端口、80端口分别发布成HTTPS、HTTP协议。

apiVersion: v1kind: Servicemetadata:  annotations:    kubernetes.io/elb.autocreate: '      {          "type": "public",          "bandwidth_name": "cce-bandwidth-1634816602057",          "bandwidth_chargemode": "traffic",          "bandwidth_size": 5,          "bandwidth_sharetype": "PER",          "eip_type": "5_bgp",          "available_zone": [              "cn-north-4b"          ],          "l7_flavor_name": "L7_flavor.elb.s2.small",          "l4_flavor_name": "L4_flavor.elb.s1.medium"      }'    kubernetes.io/elb.class: performance    kubernetes.io/elb.protocol-port: "https:443,http:80"    kubernetes.io/elb.cert-id: "17e3b4f4bc40471c86741dc3aa211379"  labels:    app: nginx    name: test  name: test  namespace: defaultspec:  ports:  - name: cce-service-0    port: 443    protocol: TCP    targetPort: 80  - name: cce-service-1    port: 80    protocol: TCP    targetPort: 80  selector:    app: nginx    version: v1  sessionAffinity: None  type: LoadBalancer

使用上面的示例创建Service,在新建的ELB实例中可以看到创建了443端口和80端口的监听器。

support.huaweicloud.com/usermanual-cce/cce_01_0014.html