Questo tutorial è rivolto agli architetti cloud e agli amministratori delle operazioni interessati a eseguire il deployment di un'applicazione web in un cluster Google Kubernetes Engine (GKE) e a esporla con un bilanciatore del carico HTTPS.
Crea un cluster GKE
Il seguente file Terraform crea un cluster GKE:
Il seguente file Terraform crea un indirizzo IP globale e una zona Cloud DNS:
Inizializza Terraform:
terraform init
Visualizza le modifiche all'infrastruttura:
terraform plan
Quando richiesto, inserisci il tuo dominio, ad esempio
my-domain.net
.Applica la configurazione Terraform:
terraform apply --auto-approve
Quando richiesto, inserisci il tuo dominio, ad esempio
my-domain.net
.L'output è simile al seguente:
Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Outputs: cluster_name = "networking-cluster" region = "us-central1"
Crea un bilanciatore del carico delle applicazioni esterno
Il seguente manifest descrive un ManagedCertificate, FrontendConfig, Deployment, Service e Ingress:
Sostituisci
DOMAIN_NAME
con il tuo nome di dominio, ad esempiomy-domain.net
.Questo manifest ha le seguenti proprietà:
networking.gke.io/managed-certificates
: il nome del ManagedCertificate.networking.gke.io/v1beta1.FrontendConfig
: il nome della risorsa FrontendConfig.kubernetes.io/ingress.global-static-ip-name
: il nome dell'indirizzo IP.kubernetes.io/ingress.class
: indica al controller GKE Ingress di creare un bilanciatore del carico delle applicazioni esterno.
Applica il manifest al cluster:
kubectl apply -f kubernetes-manifests.yaml
Verifica che Ingress sia stato creato:
kubectl describe ingress frontend
L'output è simile al seguente:
... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal ADD 2m loadbalancer-controller default/frontend Normal CREATE 1m loadbalancer-controller ip: 203.0.113.2 ...
Il provisioning di Ingress potrebbe richiedere diversi minuti.
Test dell'applicazione
Controlla lo stato del certificato SSL:
kubectl get managedcertificates.networking.gke.io networking-managed-cert
Il provisioning del certificato SSL potrebbe richiedere fino a 30 minuti. Il seguente output indica che il certificato SSL è pronto:
NAME AGE STATUS networking-managed-cert 28m Active
Esegui un comando
curl
:curl -Lv https://DOMAIN_NAME
L'output è simile al seguente:
* Trying 34.160.115.33:443... * Connected to DOMAIN_NAME (34.160.115.33) port 443 (#0) ... * TLSv1.3 (IN), TLS handshake, Certificate (11): ... * Server certificate: * subject: CN=DOMAIN_NAME ... > Host: DOMAIN_NAME