Condividi tramite


Usare Let's Encrypt certificates on gateway applicazione for AKS clusters (Usare Let's Encrypt certificates on gateway applicazione for AKS clusters )Use Let's Encrypt certificates on gateway applicazione for AKS clusters

È possibile configurare l'istanza del servizio Azure Kubernetes (servizio Azure Kubernetes) per usare Let's Encrypt e ottenere automaticamente un certificato TLS/SSL per il dominio. Il certificato viene installato nel gateway di app Azure lication, che esegue la terminazione TLS/SSL per il cluster del servizio Azure Kubernetes.

La configurazione descritta in questo articolo usa il componente aggiuntivo Kubernetes cert-manager , che automatizza la creazione e la gestione dei certificati.

Suggerimento

Prendere in considerazione gateway applicazione per i contenitori per la soluzione di ingresso Kubernetes.

Installare il componente aggiuntivo

Usare la procedura seguente per installare cert-manager nel cluster del servizio Azure Kubernetes esistente:

  1. Eseguire lo script seguente per installare il grafico Helm di cert-manager. Lo script esegue le azioni seguenti:

    • Crea un nuovo cert-manager spazio dei nomi nel cluster del servizio Azure Kubernetes
    • Crea le definizioni di risorse personalizzate seguenti :Certificate, Challenge, ClusterIssuer, IssuerOrder
    • Installa il grafico cert-manager (dal sito cert-manager)
    #!/bin/bash
    
    # Install the CustomResourceDefinition resources separately
    kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.16.1/cert-manager.crds.yaml
    
    # Create the namespace for cert-manager
    kubectl create namespace cert-manager
    
    # Label the cert-manager namespace to disable resource validation
    kubectl label namespace cert-manager cert-manager.io/disable-validation=true
    
    # Add the Jetstack Helm repository
    helm repo add jetstack https://charts.jetstack.io
    
    # Update your local Helm chart repository cache
    helm repo update
    
    # Install the cert-manager Helm chart
    # Helm v3+
    helm install \
      cert-manager jetstack/cert-manager \
      --namespace cert-manager \
      --version v1.16.1 \
      # --set installCRDs=true
    
    # To automatically install and manage the CRDs as part of your Helm release,
    # you must add the --set installCRDs=true flag to your Helm installation command.
    
  2. Creare una ClusterIssuer risorsa. Cert-manager richiede questa risorsa per rappresentare l'autorità di certificazione Let's Encrypt che rilascia il certificato firmato.

    Cert-manager usa la ClusterIssuer risorsa non-namespaced per rilasciare certificati che possono essere utilizzati da più spazi dei nomi. Crittografa usa il protocollo ACME per verificare di controllare un determinato nome di dominio e rilasciare un certificato. È possibile ottenere altri dettagli sulla configurazione delle ClusterIssuer proprietà nella documentazione di cert-manager.

    ClusterIssuer indica a cert-manager di rilasciare certificati usando l'ambiente di gestione temporanea Let's Encrypt usato per il test. Il certificato radice non è presente negli archivi attendibili del browser/client.

    Il tipo di verifica predefinito nel codice YAML seguente è http01. È possibile trovare altri tipi di verifica nella documentazione let's Encrypt.

    Nel codice YAML seguente assicurarsi di sostituire <YOUR.EMAIL@ADDRESS> con le informazioni.

    #!/bin/bash
    kubectl apply -f - <<EOF
    apiVersion: cert-manager.io/v1
    kind: ClusterIssuer
    metadata:
      name: letsencrypt-staging
    spec:
      acme:
        # You must replace this email address with your own.
        # Let's Encrypt uses this to contact you about expiring
        # certificates, and issues related to your account.
        email: <YOUR.EMAIL@ADDRESS>
        # ACME server URL for Let's Encrypt's staging environment.
        # The staging environment won't issue trusted certificates but is
        # used to ensure that the verification process is working properly
        # before moving to production
        server: https://acme-staging-v02.api.letsencrypt.org/directory
        privateKeySecretRef:
          # Secret resource used to store the account's private key.
          name: example-issuer-account-key
        # Enable the HTTP-01 challenge provider
        # you prove ownership of a domain by ensuring that a particular
        # file is present at the domain
        solvers:
          - http01:
            ingress:
             #   class: azure/application-gateway
               ingressTemplate:
                 metadata:
                   annotations:
                     kubernetes.io/ingress.class: azure/application-gateway
    EOF
    
  3. Creare una risorsa di ingresso per esporre l'applicazione guestbook usando la distribuzione gateway applicazione con il certificato Let's Encrypt.

    Assicurarsi che la distribuzione gateway applicazione abbia una configurazione IP front-end pubblica con un nome DNS. Usare il dominio predefinito azure.com o effettuare il provisioning di una zona DNS di Azure e quindi assegnare un dominio personalizzato. L'annotazione certmanager.k8s.io/cluster-issuer: letsencrypt-staging indica a cert-manager di elaborare la risorsa di ingresso con tag.

    Nel codice YAML seguente assicurarsi di sostituire <PLACEHOLDERS.COM> con il proprio dominio o con il dominio gateway applicazione (ad esempio, kh-aks-ingress.westeurope.cloudapp.azure.com).

    kubectl apply -f - <<EOF
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: guestbook-letsencrypt-staging
      annotations:
        kubernetes.io/ingress.class: azure/application-gateway
        cert-manager.io/cluster-issuer: letsencrypt-staging
    spec:
      tls:
      - hosts:
        - <PLACEHOLDERS.COM>
        secretName: guestbook-secret-name
      rules:
      - host: <PLACEHOLDERS.COM>
          http:
          paths:
          - backend:
              serviceName: frontend
              servicePort: 80
    EOF
    

    Dopo alcuni secondi, è possibile accedere al guestbook servizio tramite l'URL HTTPS gateway applicazione usando il certificato Let's Encrypt automaticamente per la gestione temporanea.

    Il browser potrebbe avvisare l'utente di un'autorità di certificazione non valida. Il motivo è che CN=Fake LE Intermediate X1 ha emesso il certificato di gestione temporanea. Questo avviso indica che il sistema funziona come previsto e si è pronti per il certificato di produzione.

  4. Dopo aver configurato correttamente il certificato di gestione temporanea, è possibile passare a un server ACME di produzione:

    1. Sostituire l'annotazione di staging nella risorsa in ingresso con cert-manager.io/cluster-issuer: letsencrypt-prod.
    2. Eliminare la risorsa di staging ClusterIssuer esistente creata in precedenza. Creare una nuova risorsa di staging sostituendo il server ACME dal file YAML precedente ClusterIssuer con https://acme-v02.api.letsencrypt.org/directory.

Prima della scadenza del certificato Let's Encrypt, cert-manager aggiorna automaticamente il certificato nell'archivio segreti Kubernetes. A questo punto, il controller di ingresso gateway applicazione applica il segreto aggiornato a cui fa riferimento nelle risorse in ingresso usate per configurare gateway applicazione.