All Products
Search
Document Center

Container Service for Kubernetes:Konfigurasikan sertifikat HTTPS

Last Updated:Jun 23, 2026

Dengan mengonfigurasi sertifikat HTTPS, Anda dapat mengaktifkan enkripsi Transport Layer Security (TLS)/Secure Sockets Layer (SSL) untuk layanan yang diterapkan pada gateway MSE Ingress. Ini merupakan langkah penting untuk mengamankan data pada aplikasi web modern dan layanan API. Sertifikat HTTPS memastikan bahwa data yang ditransmisikan antara klien dan gateway dienkripsi, sehingga mencegah pihak tidak sah mencuri atau mengubah informasi sensitif, serta memberikan perlindungan kuat terhadap serangan man-in-the-middle.

Prasyarat

Metode konfigurasi

Gateway MSE Ingress mendukung dua metode untuk mengonfigurasi sertifikat HTTPS: menggunakan Kubernetes Secret atau menggunakan Konsol MSE.

Item

Kubernetes Secret

MSE console

Use cases

  • Manage certificates declaratively.

  • Automate certificate management with CI/CD pipelines or tools like cert-manager.

  • Manage certificates centrally on the Certificate Management Service console.

  • Apply a single certificate to multiple cloud products, such as Web Application Firewall (WAF) and Server Load Balancer (SLB).

  • Deploy or replace certificates in batches.

Priority

Low

High

Cross-namespace

Not supported.

Supported.

Certificate update

Replace the content of the Kubernetes Secret.

Replace the certificate on the MSE console or deploy a new certificate on the Certificate Management Service console.

Terapkan layanan backend

  1. Masuk ke Konsol Container Service for Kubernetes (ACK). Di panel navigasi kiri, klik Clusters.

  2. Pada halaman Clusters, klik nama kluster target Anda. Di panel navigasi kiri, pilih Workloads > Deployments.

  3. Pada halaman Deployments, klik Create from YAML. Gunakan YAML berikut untuk menerapkan Deployment httpbin dan Service httpbin.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: httpbin
      namespace: default
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: httpbin
      template:
        metadata:
          labels:
            app: httpbin
            version: v1
        spec:
          containers:
            - image: registry.cn-hangzhou.aliyuncs.com/mse-ingress/go-httpbin
              args:
                - "--version=v1"
              imagePullPolicy: Always
              name: httpbin
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: httpbin
      namespace: default
    spec:
      ports:
        - port: 8080
          protocol: TCP
      selector:
        app: httpbin

Konfigurasikan sertifikat HTTPS

Kubernetes Secret

Anda dapat mengonfigurasi sertifikat HTTPS untuk domain dengan mereferensikan Kubernetes Secret menggunakan semantik Ingress native.

  1. Siapkan sertifikat domain. Contoh ini menggunakan sertifikat tanda tangan sendiri.

    Catatan

    Untuk lingkungan produksi, Anda harus menggunakan kunci privat dan sertifikat asli untuk bisnis Anda. Anda dapat mengunduh kunci dan sertifikat untuk domain Anda dari Konsol Certificate Management Service.

    1. Jalankan perintah berikut untuk menghasilkan file sertifikat tls.crt dan file kunci privat tls.key.

      openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=foo.bar.com/O=foo.bar.com"
    2. Buat Secret untuk menyimpan sertifikat TLS.

      1. Masuk ke Konsol Container Service for Kubernetes (ACK). Di panel navigasi kiri, klik Clusters.

      2. Pada halaman Clusters, klik nama kluster target Anda. Di panel navigasi kiri, pilih Configurations > Secrets.

      3. Klik Create. Di panel Create, atur Name menjadi tls-test, pilih Type sebagai TLS Certificate, salin konten tls.crt dan tls.key yang telah dibuat ke kotak input yang sesuai, lalu klik Create.

  2. Buat MSE Ingress dan konfigurasikan sertifikat HTTPS untuk domain foo.bar.com.

    1. Di panel navigasi kiri, pilih Network > Ingresses.

    2. Pada halaman Ingresses, klik Create Ingress. Di dialog Create Ingress, konfigurasi entri rute.

      Parameter

      Description

      Example

      Gateway type

      Select MSE Ingress. For a comparison of different gateway types, see Comparison of Nginx Ingress, ALB Ingress, APIG Ingress, and MSE Ingress.

      MSE Ingress

      Name

      Enter a custom name for the Ingress.

      test

      IngressClass

      Select the relevant resource class.

      mse

      Rule

      Click + Add Rule to add routing rules.

      • Domain name: A custom domain name.

      • Path mapping: Configure the following parameters.

        • Path: The URL path for accessing the service.

        • Match rule:

          • Prefix (prefix-based match): Matches the prefix of the request URL path.

          • Exact (exact match): Exactly matches the request URL path.

          • Default (implementation-specific): The behavior is determined by the specific logic of the Ingress controller.

          For more information, see Advanced features of ALB Ingresses.

        • Service: The target Kubernetes Service.

        • Port: The port to expose for the service.

      • Ingress supports multiple paths under the same domain name. Click + Add Path to add more paths.

      • Domain name: foo.bar.com

      • Path mapping:

        • Path: /

        • Match rule: Prefix (prefix-based match)

        • Service: httpbin

        • Port: 8080

      TLS configuration

      Enable TLS to configure a secure routing service.

      • Domain name: A custom domain name.

      • Secret: Select the appropriate Secret.

        Note

        Leaving this empty enables certificate auto-discovery.

        To create a new Secret:

        1. To the right of the Secret field, click Create.

        2. In the Create Secret dialog box, specify a Name, Cert, and Key for the Secret, and then click OK.

        3. From the Secret drop-down list, select the Secret you created.

      Click + Add TLS Configuration to configure multiple TLS settings.

      • Domain name: foo.bar.com

      • Secret: tls-test

    3. Biarkan pengaturan lainnya tetap default dan klik OK pada halaman Create Ingress.

  3. Uji trafik HTTPS. Jalankan perintah berikut, ganti x.x.x.x dengan alamat IP gateway aktual Anda. Anda dapat menemukan alamat IP gateway di halaman daftar Ingresses.

    Catatan

    Contoh ini menggunakan sertifikat tanda tangan sendiri dan domain yang tidak terdaftar di penyedia DNS. Oleh karena itu, Anda harus menggunakan flag --resolve untuk menyelesaikan nama domain ke alamat IP gateway secara manual dan flag -k untuk melewati validasi sertifikat.

    curl -v -k https://foo.bar.com/version --resolve "foo.bar.com:443:x.x.x.x"

    Output yang diharapkan adalah sebagai berikut:

    * Connected to foo.bar.com (X.X.X.X) port 443 (#0)
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * successfully set certificate verify locations:
    *   CAfile: /etc/ssl/cert.pem
      CApath: none
    * TLSv1.2 (OUT), TLS handshake, Client hello (1):
    * TLSv1.2 (IN), TLS handshake, Server hello (2):
    * TLSv1.2 (IN), TLS handshake, Certificate (11):
    * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
    * TLSv1.2 (IN), TLS handshake, Server finished (14):
    * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
    * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
    * TLSv1.2 (OUT), TLS handshake, Finished (20):
    * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
    * TLSv1.2 (IN), TLS handshake, Finished (20):
    * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
    * ALPN, server accepted to use http/1.1
    * Server certificate:
    *  subject: CN=foo.bar.com; O=foo.bar.com
    *  start date: Jan 17 06:47:23 2024 GMT
    *  expire date: Jan 16 06:47:23 2025 GMT
    *  issuer: CN=foo.bar.com; O=foo.bar.com
    *  SSL certificate verify result: self signed certificate (18), continuing anyway.
    > GET /version HTTP/1.1
    > Host: foo.bar.com
    > User-Agent: curl/7.64.1
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < date: Wed, 17 Jan 2024 07:49:39 GMT
    < content-length: 53
    < content-type: text/plain; charset=utf-8
    < req-cost-time: 3
    < req-arrive-time: 1705477779046
    < resp-start-time: 1705477779049
    < x-envoy-upstream-service-time: 2
    < server: istio-envoy
    <
    version: v1
    hostname: httpbin-xxxxxx

MSE console

Anda dapat mengonfigurasi sertifikat untuk domain langsung di Konsol MSE. Metode ini tidak mengharuskan Anda mereferensikan Kubernetes Secret dalam objek Ingress; Anda hanya perlu mengonfigurasi aturan routing.

Penting

Untuk nama domain yang sama, metode Konsol MSE memiliki prioritas lebih tinggi daripada metode Kubernetes Secret. Jika Anda mengonfigurasi sertifikat untuk domain yang sama baik di Konsol MSE maupun pada resource Ingress Kubernetes, sertifikat dari konsol yang akan digunakan.

  1. Siapkan sertifikat domain dan unggah ke Alibaba Cloud Certificate Management Service. Untuk informasi selengkapnya, lihat Unggah, sinkronkan, dan bagikan sertifikat SSL. Jika sertifikat Anda sudah dihosting di Certificate Management Service, Anda dapat melewati langkah ini.

  2. Buat domain dan konfigurasikan sertifikatnya.

    1. Masuk ke Konsol Manajemen Gateway MSE dan pilih wilayah di bilah navigasi atas.

    2. Di panel navigasi kiri, pilih Cloud-native Gateway > Gateways, lalu klik ID instans gateway target.

    3. Di panel navigasi kiri, klik Routes, lalu pilih tab Domain.

    4. Klik Add domain name. Tambahkan Domain name, atur Protocol ke HTTPS, lalu pilih sertifikat yang sesuai.

  3. Buat layanan.

    1. Pada halaman Manajemen Rute instans MSE, pilih tab Service dan klik Create service.

    2. Atur Service Sources ke Container service, pilih Namespaces yang sesuai, centang layanan httpbin yang telah Anda buat sebelumnya di Service list, lalu klik OK.

  4. Buat entri rute.

    1. Pada halaman Manajemen Rute instans MSE, pilih tab Route dan klik Create route.

    2. Untuk Domain name, pilih domain yang Anda tambahkan di Langkah 2. Untuk Backend service, pilih layanan yang Anda buat di Langkah 3, lalu klik Save and publish.

  5. Uji trafik HTTPS. Jalankan perintah berikut, ganti x.x.x.x dengan alamat IP gateway aktual Anda. Anda dapat menemukan alamat IP gateway di halaman .

    Catatan

    Jika Anda menggunakan sertifikat tanda tangan sendiri dan domain tidak terdaftar di penyedia DNS, Anda harus menggunakan flag --resolve untuk menyelesaikan nama domain ke alamat IP gateway secara manual dan flag -k untuk melewati validasi sertifikat.

    Ganti <Your-DomainName> dengan nama domain aktual Anda.

    curl -v -k https://<Your-DomainName>/version --resolve "<Your-DomainName>:443:x.x.x.x"

    Output yang diharapkan adalah sebagai berikut:

    * Connected to ********** (X.X.X.X) port 443 (#0)
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * successfully set certificate verify locations:
    *   CAfile: /etc/ssl/cert.pem
      CApath: none
    * TLSv1.2 (OUT), TLS handshake, Client hello (1):
    * TLSv1.2 (IN), TLS handshake, Server hello (2):
    * TLSv1.2 (IN), TLS handshake, Certificate (11):
    * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
    * TLSv1.2 (IN), TLS handshake, Server finished (14):
    * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
    * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
    * TLSv1.2 (OUT), TLS handshake, Finished (20):
    * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
    * TLSv1.2 (IN), TLS handshake, Finished (20):
    * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
    * ALPN, server accepted to use http/1.1
    * Server certificate:
    *  subject: CN=*********; O=**********
    *  start date: Jan 17 06:47:23 2024 GMT
    *  expire date: Jan 16 06:47:23 2025 GMT
    *  issuer: CN=**********; O=**********
    *  SSL certificate verify result: self signed certificate (18), continuing anyway.
    > GET /version HTTP/1.1
    > Host: **********
    > User-Agent: curl/7.64.1
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < date: Wed, 17 Jan 2024 08:16:27 GMT
    < content-length: 46
    < content-type: text/plain; charset=utf-8
    < req-cost-time: 5
    < req-arrive-time: 1705479387567
    < resp-start-time: 1705479387573
    < x-envoy-upstream-service-time: 4
    < server: istio-envoy
    <
    version: v1
    hostname: httpbin-xxxxxx