Questa pagina mostra come eseguire il deployment di Cloud Service Broker Kf per Google Cloud e utilizzarlo per eseguire il provisioning o il deprovisioning delle risorse di supporto. Per saperne di più su Kf Cloud Service Broker, consulta i concetti e l'architettura.
Creare variabili di ambiente
Linux
export PROJECT_ID=YOUR_PROJECT_ID export CLUSTER_PROJECT_ID=YOUR_PROJECT_ID export CLUSTER_NAME=kf-cluster export INSTANCE_NAME=cloud-service-broker export COMPUTE_REGION=us-central1
Windows PowerShell
Set-Variable -Name PROJECT_ID -Value YOUR_PROJECT_ID Set-Variable -Name CLUSTER_PROJECT_ID -Value YOUR_PROJECT_ID Set-Variable -Name CLUSTER_NAME -Value kf-cluster Set-Variable -Name INSTANCE_NAME -Value cloud-service-broker Set-Variable -Name COMPUTE_REGION -Value us-central1
configura il database Kf Cloud Service Broker
Crea un'istanza Cloud SQL per MySQL.
gcloud sql instances create ${INSTANCE_NAME} --cpu=2 --memory=7680MB --require-ssl --region=${COMPUTE_REGION}
Crea un database denominato
servicebroker
nell'istanza Cloud SQL per MySQL.gcloud sql databases create servicebroker -i ${INSTANCE_NAME}
Crea un nome utente e una password da utilizzare da Cloud Service Broker Kf.
gcloud sql users create csbuser -i ${INSTANCE_NAME} --password=csbpassword
Configurare un account di servizio Google (GSA) per il service broker Kf Cloud
Crea un account di servizio Google.
gcloud iam service-accounts create csb-${CLUSTER_NAME}-sa \ --project=${CLUSTER_PROJECT_ID} \ --description="GSA for CSB at ${CLUSTER_NAME}" \ --display-name="csb-${CLUSTER_NAME}"
Concedi le autorizzazioni
roles/cloudsql.client
all'account di servizio. Questo è necessario per connettere il pod Kf Cloud Service Broker all'istanza Cloud SQL per MySQL tramite il proxy di autenticazione Cloud SQL.gcloud projects add-iam-policy-binding ${CLUSTER_PROJECT_ID} \ --member="serviceAccount:csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com" \ --role="roles/cloudsql.client"
Concedi autorizzazioni Google Cloud aggiuntive all'account di servizio.
gcloud projects add-iam-policy-binding ${CLUSTER_PROJECT_ID} \ --member="serviceAccount:csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com" \ --role="roles/compute.networkUser"
gcloud projects add-iam-policy-binding ${CLUSTER_PROJECT_ID} \ --member="serviceAccount:csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com" \ --role="roles/cloudsql.admin"
gcloud projects add-iam-policy-binding ${CLUSTER_PROJECT_ID} \ --member="serviceAccount:csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com" \ --role="roles/redis.admin"
Verifica le autorizzazioni.
gcloud projects get-iam-policy ${CLUSTER_PROJECT_ID} \ --filter='bindings.members:serviceAccount:"CSB_SERVICE_ACCOUNT_NAME"' \ --flatten="bindings[].members"
Configurazione di Workload Identity per il service broker Kf Cloud
Associa l'account di servizio Google all'account di servizio Kubernetes.
gcloud iam service-accounts add-iam-policy-binding "csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com" \ --project=${CLUSTER_PROJECT_ID} \ --role="roles/iam.workloadIdentityUser" \ --member="serviceAccount:${CLUSTER_PROJECT_ID}.svc.id.goog[kf-csb/csb-user]"
Verifica il vincolo.
gcloud iam service-accounts get-iam-policy "csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com" \ --project=${CLUSTER_PROJECT_ID}
Configura un secret Kubernetes per condividere la configurazione con Cloud Service Broker Kf
Crea un file config.yml.
cat << EOF >> ./config.yml gcp: credentials: "" project: ${CLUSTER_PROJECT_ID}
db: host: 127.0.0.1 password: csbpassword user: csbuser tls: false api: user: servicebroker password: password EOF
Crea lo spazio dei nomi
kf-csb
.kubectl create ns kf-csb
Crea il secret di Kubernetes.
kubectl create secret generic csb-secret --from-file=config.yml -n kf-csb
Installare Kf Cloud Service Broker
Scarica il
kf-csb.yml
.gcloud storage cp gs://kf-releases/csb/v1.0.0/kf-csb.yaml /tmp/kf-csb.yaml
Modifica
/tmp/kf-csb.yaml
e sostituisci i segnaposto con i valori finali. Nell'esempio seguente viene utilizzatosed
.sed -i "s|<GSA_NAME>|csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com|g" /tmp/kf-csb.yaml
sed -i "s|<INSTANCE_CONNECTION_NAME>|${CLUSTER_PROJECT_ID}:${COMPUTE_REGION}:${INSTANCE_NAME}|g" /tmp/kf-csb.yaml
sed -i "s|<DB_PORT>|3306|g" /tmp/kf-csb.yaml
Applica YAML per Kf Cloud Service Broker.
kubectl apply -f /tmp/kf-csb.yaml
Verifica lo stato di installazione di Cloud Service Broker Kf.
kubectl get pods -n kf-csb
Creare un Service Broker
kf create-service-broker cloud-service-broker servicebroker password http://csb-controller.kf-csb/
Convalida l'installazione
Verifica la presenza di servizi disponibili nel marketplace.
kf marketplace
Se tutto è installato e configurato correttamente, dovresti vedere quanto segue:
$ kf marketplace
Broker Name Namespace Description
cloud-service-broker csb-google-bigquery A fast, economical and fully managed data warehouse for large-scale data analytics.
cloud-service-broker csb-google-dataproc Dataproc is a fully-managed service for running Apache Spark and Apache Hadoop clusters in a simpler, more cost-efficient way.
cloud-service-broker csb-google-mysql Mysql is a fully managed service for the Google Cloud Platform.
cloud-service-broker csb-google-postgres PostgreSQL is a fully managed service for the Google Cloud Platform.
cloud-service-broker csb-google-redis Cloud Memorystore for Redis is a fully managed Redis service for the Google Cloud Platform.
cloud-service-broker csb-google-spanner Fully managed, scalable, relational database service for regional and global application data.
cloud-service-broker csb-google-stackdriver-trace Distributed tracing service
cloud-service-broker csb-google-storage-bucket Google Cloud Storage that uses the Terraform back-end and grants service accounts IAM permissions directly on the bucket.
Passaggi successivi
- Testa Cloud Service Broker Kf con la nostra guida a Spring Music.
Esegui la pulizia
Elimina cloud-service-broker.
kf delete-service-broker cloud-service-broker
Elimina i componenti CSB.
kubectl delete ns kf-csb
Elimina l'istanza Cloud SQL per MySQL di Cloud Service Broker Kf.
gcloud sql instances delete ${INSTANCE_NAME} --project=${CLUSTER_PROJECT_ID}
Rimuovi le associazioni dei criteri IAM.
gcloud projects remove-iam-policy-binding ${CLUSTER_PROJECT_ID} \ --member='serviceAccount:csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com' \ --role=roles/cloudsql.client
gcloud projects remove-iam-policy-binding ${CLUSTER_PROJECT_ID} \ --member='serviceAccount:csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com' \ --role=roles/compute.networkUser
gcloud projects remove-iam-policy-binding ${CLUSTER_PROJECT_ID} \ --member='serviceAccount:csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com' \ --role=roles/redis.admin
Rimuovi la soluzione.
gcloud iam service-accounts delete csb-${CLUSTER_NAME}-sa@${CLUSTER_PROJECT_ID}.iam.gserviceaccount.com \ --project=${CLUSTER_PROJECT_ID}