Bagikan melalui


Offloading SSL dengan Application Gateway untuk Kontainer - GATEWAY API

Dokumen ini membantu menyiapkan contoh aplikasi yang menggunakan sumber daya berikut dari Gateway API. Langkah-langkah disediakan untuk:

Latar belakang

Application Gateway untuk Kontainer memungkinkan offloading SSL untuk performa backend yang lebih baik. Lihat contoh skenario berikut:

Gambar yang menunjukkan offloading SSL dengan Application Gateway untuk Kontainer.

Prasyarat

  1. Jika mengikuti strategi penyebaran BYO, pastikan Anda menyiapkan Application Gateway untuk sumber daya Kontainer dan Pengontrol ALB

  2. Jika mengikuti strategi penyebaran terkelola ALB, pastikan Anda menyediakan Pengontrol ALB dan Application Gateway untuk sumber daya Kontainer melalui sumber daya kustom ApplicationLoadBalancer.

  3. Terapkan contoh aplikasi HTTPS Terapkan file deployment.yaml berikut pada kluster Anda untuk membuat aplikasi web sampel untuk menunjukkan offloading TLS/SSL.

    kubectl apply -f https://trafficcontrollerdocs.blob.core.windows.net/examples/https-scenario/ssl-termination/deployment.yaml
    

    Perintah ini membuat yang berikut ini pada kluster Anda:

    • namespace yang dipanggil test-infra
    • satu layanan yang dipanggil echo di test-infra namespace layanan
    • satu penyebaran yang dipanggil echo di test-infra namespace
    • satu rahasia yang dipanggil listener-tls-secret di test-infra namespace

Menyebarkan sumber daya API Gateway yang diperlukan

  1. Membuat Gateway

    kubectl apply -f - <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: gateway-01
      namespace: test-infra
      annotations:
        alb.networking.azure.io/alb-namespace: alb-test-infra
        alb.networking.azure.io/alb-name: alb-test
    spec:
      gatewayClassName: azure-alb-external
      listeners:
      - name: https-listener
        port: 443
        protocol: HTTPS
        allowedRoutes:
          namespaces:
            from: Same
        tls:
          mode: Terminate
          certificateRefs:
          - kind : Secret
            group: ""
            name: listener-tls-secret
    EOF
    

Catatan

Saat Pengontrol ALB membuat Application Gateway untuk sumber daya Kontainer di ARM, pengontrol tersebut akan menggunakan konvensi penamaan berikut untuk sumber daya frontend: fe-8< karakter yang dihasilkan secara acak>

Jika Anda ingin mengubah nama frontend yang dibuat di Azure, pertimbangkan untuk mengikuti strategi bawa penyebaran Anda sendiri.

Saat sumber daya gateway dibuat, pastikan status valid, pendengar diprogram, dan alamat ditetapkan ke gateway.

kubectl get gateway gateway-01 -n test-infra -o yaml

Contoh output pembuatan gateway yang berhasil.

status:
  addresses:
  - type: Hostname
    value: xxxx.yyyy.alb.azure.com
  conditions:
  - lastTransitionTime: "2023-06-19T21:04:55Z"
    message: Valid Gateway
    observedGeneration: 1
    reason: Accepted
    status: "True"
    type: Accepted
  - lastTransitionTime: "2023-06-19T21:04:55Z"
    message: Application Gateway For Containers resource has been successfully updated.
    observedGeneration: 1
    reason: Programmed
    status: "True"
    type: Programmed
  listeners:
  - attachedRoutes: 0
    conditions:
    - lastTransitionTime: "2023-06-19T21:04:55Z"
      message: ""
      observedGeneration: 1
      reason: ResolvedRefs
      status: "True"
      type: ResolvedRefs
    - lastTransitionTime: "2023-06-19T21:04:55Z"
      message: Listener is accepted
      observedGeneration: 1
      reason: Accepted
      status: "True"
      type: Accepted
    - lastTransitionTime: "2023-06-19T21:04:55Z"
      message: Application Gateway For Containers resource has been successfully updated.
      observedGeneration: 1
      reason: Programmed
      status: "True"
      type: Programmed
    name: https-listener
    supportedKinds:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute

Setelah gateway dibuat, buat sumber daya HTTPRoute.

kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: https-route
  namespace: test-infra
spec:
  parentRefs:
  - name: gateway-01
  rules:
  - backendRefs:
    - name: echo
      port: 80
EOF

Setelah sumber daya HTTPRoute dibuat, pastikan rute Diterima dan sumber daya Application Gateway for Containers diprogram.

kubectl get httproute https-route -n test-infra -o yaml

Verifikasi bahwa sumber daya Application Gateway untuk Kontainer berhasil diperbarui.

status:
  parents:
  - conditions:
    - lastTransitionTime: "2023-06-19T22:18:23Z"
      message: ""
      observedGeneration: 1
      reason: ResolvedRefs
      status: "True"
      type: ResolvedRefs
    - lastTransitionTime: "2023-06-19T22:18:23Z"
      message: Route is Accepted
      observedGeneration: 1
      reason: Accepted
      status: "True"
      type: Accepted
    - lastTransitionTime: "2023-06-19T22:18:23Z"
      message: Application Gateway For Containers resource has been successfully updated.
      observedGeneration: 1
      reason: Programmed
      status: "True"
      type: Programmed
    controllerName: alb.networking.azure.io/alb-controller
    parentRef:
      group: gateway.networking.k8s.io
      kind: Gateway
      name: gateway-01
      namespace: test-infra

Menguji akses ke aplikasi

Sekarang kami siap untuk mengirim beberapa lalu lintas ke aplikasi sampel kami, melalui FQDN yang ditetapkan ke frontend. Gunakan perintah berikut untuk mendapatkan FQDN.

fqdn=$(kubectl get gateway gateway-01 -n test-infra -o jsonpath='{.status.addresses[0].value}')

Curling FQDN ini harus mengembalikan respons dari backend seperti yang dikonfigurasi pada HTTPRoute.

curl --insecure https://$fqdn/

Selamat, Anda telah menginstal Pengontrol ALB, menyebarkan aplikasi backend dan merutekan lalu lintas ke aplikasi melalui ingress di Application Gateway untuk Kontainer.