Updated on 2026-08-29 GMT+08:00

Redirecting HTTP to HTTPS for a LoadBalancer Ingress

Ingresses can forward HTTP access requests to HTTPS listeners. The following example redirects requests for example.com/test to HTTPS port 443.

Prerequisites

Constraints

If the cluster version is v1.23.14-r0, v1.25.9-r0, v1.28.4-r0, or later, HTTP to HTTPS redirection can only be configured for ingresses using a dedicated load balancer.

If the cluster version is v1.27.16-r50, v1.28.15-r40, v1.29.15-r0, v1.30.14-r0, v1.31.10-r0, v1.32.6-r0, v1.33.1-r0, or later, HTTP to HTTPS redirection can also be configured for ingresses using a shared load balancer.

Redirecting HTTP to HTTPS

You can configure HTTP to HTTPS redirection using either the CCE console or kubectl.

You can use annotations to redirect the requests of an ingress to an HTTPS listener. The following is an example:

  1. Use kubectl to access the cluster. For details, see Accessing a Cluster Using kubectl.
  2. Create a YAML file named ingress-test.yaml. The file name can be customized.

    vi ingress-test.yaml

    An example YAML file of an ingress associated with an existing load balancer is as follows:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: test-redirect-listener
      namespace: default
      annotations:
        kubernetes.io/elb.id: df76342f-e898-402a-bac8-bde5bf974da8    # Load balancer ID
        kubernetes.io/elb.class: performance # Load balancer type
        kubernetes.io/elb.listen-ports: '[{"HTTP":80},{"HTTPS":443}]'             # Multi-port configuration
        kubernetes.io/elb.ssl-redirect: 'true'        # Enable redirection from HTTP to HTTPS.
        kubernetes.io/elb.tls-certificate-ids: 6cfb43c9de1a41a18478b868e34b0a82       # HTTPS listener server certificate
    spec:
      rules:
        - host: ''
          http:
            paths:
              - path: /
                backend:
                  service:
                    name: test-service  # Replace it with your target Service name.
                    port:
                      number: 80   # Replace it with your target Service port.
                property:
                  ingress.beta.kubernetes.io/url-match-mode: STARTS_WITH
                pathType: ImplementationSpecific
      ingressClassName: cce
    Table 1 Key parameters

    Parameter

    Mandatory

    Type

    Description

    kubernetes.io/elb.listen-ports

    Yes

    String

    Multi-port listening configuration. After configuration, this setting cannot be modified.

    Format: The value is a JSON string, for example:

    [{"HTTP":80},{"HTTPS":443}]

    Parameter: The port number ranges from 1 to 65535.

    NOTE:

    You can configure this annotation along with the one for enabling HTTP/2, but HTTP/2 takes effect only on HTTPS ports.

    kubernetes.io/elb.ssl-redirect

    Yes

    String

    Whether to enable redirection from HTTP to HTTPS.

    Format: The value can be true or false.

    Parameter: true indicates that redirection is enabled. If the value is false or the parameter is unavailable, redirection is disabled.

    NOTE:

    Either this annotation or the annotation of a grayscale release can be configured.

  3. Create an ingress.

    kubectl create -f ingress-test.yaml

    If information similar to the following is displayed, the ingress has been created:

    ingress.networking.k8s.io/ingress-test created

  4. Check the created ingress.

    kubectl get ingress

    If information similar to the following is displayed, the ingress has been created:

    NAME                    CLASS    HOSTS     ADDRESS          PORTS   AGE
    test-redirect-listener  cce      *         121.**.**.**     80      10s