23# Flyte on GCP
Prerequisites:
Procedure:
-
Create a project on GCP and get its
PROJECT_ID
:gcloud projects list
NOTE: learn how to setup the gcloud CLI here
-
Take note of the
PROJECT_NUMBER
-
Acquire credentials to access the new project:
gcloud auth application-default login
-
Create a bucket in the project and region where you will deploy Flyte, leaving public access off.
-
Go to
locals.tf
and change the following variables to your environment specifics:
Key | Value | Notes |
---|---|---|
application |
Use your own/leave default | This is just a label |
environment |
Use your own/leave default | This is just a label |
project_id |
your GPC project ID | |
dns-domain |
A DNS domain you own, so SSL certificates can be generated | |
region |
The GCP region you'll use | |
email |
Set the email where Let's Encrypt will contact you about expiring certificates | |
project_number |
Unique per GCP project, used to form a unique name for GCS buckets |
- Save your changes.
- Go to
terraform.tf
and replace the name of the GCS bucket you created in step 2 in the appropiate section:
backend "gcs" {
bucket = <your-GCS-state-bucket>
}
- Initialize your Terraform environment:
terraform init
- Then:
terraform plan
- Verify changes to be applied and run:
terraform apply
Example output:
Apply complete! Resources: 57 added, 0 changed, 0 destroyed.
Outputs:
gke_cluster_name = "flyte-gcp"
Once everything is installed:
- Generate the
kubeconfig
entry for your new GKE cluster:
gcloud container clusters get-credentials <gke-cluster-name> --region <your-GCP-region> --project <your-project_id>
- Obtain the IP address for your Ingress resource:
kubectl get ingress -n flyte
Example output:
NAME CLASS HOSTS ADDRESS PORTS AGE
flyte-core <none> flyteontf.uniondemo.run 35.237.42.230 80, 443 3m1s
flyte-core-grpc <none> flyteontf.uniondemo.run 35.237.42.230 80, 443 3m1s
- Create a DNS
A
record in a zone you own, pointing to the Ingress IP.
NOTE: it may take a while before
cert-manager
can issue a certificate for your deployment, especially because for that process to work, the FQDN of your deployment needs to be resolvable and DNS propagation takes time.
- Update your
$HOME\.flyte\config,yaml
and makeendpoint
your DNS name:
...
#Example
endpoint: dns:///flyteontf.uniondemo.run
insecure: false #it means, the connection uses SSL, even if it's a temporary cert-manager cert.
#Uncomment only if you want to test CLI commands and the certificate is not generated yet.
# You can confirm the cert by either going to the UI (a valid certificate should be used) or
#from your terminal: kubectl get challenges.acme.cert-manager.io -n flyte (there should not be any pending challenge). With this flag enabled, SSL is still used but the client doesn't verify the certificate chain.
#insecureSkipVerify: true
NOTE: this is only needed for CLI access (
flytectl
orpyflyte
)
- In your browser, go to
https://<your-DNS-record>/console
WARNING: At this point, Flyte's UI would be exposed to the Internet. We stronly encourage you to add authentication to your deployment by following the documentation
NOTE: Read more about authentication to Artifact Registry using Access Tokens here
- Create a key for the Google Service Account you'll be impersonating in order to push Images to Artifact Registry:
NOTE: in this example we're using
flyte
as the value forlocal.application
andgcp
forlocal.environment
. Replace to match what you indicated in thelocals.tf
file
gcloud iam service-accounts keys create gcp-artifact-writer.key --iam-account=flyte-gcp-registrywriter@<YOUR-GCP-PROJECT_ID>.iam.gserviceaccount.com
- Activate the Service Account in your gcloud session:
gcloud auth activate-service-account flyte-gcp-registrywriter@<YOUR-GPC-PROJECT_ID>.iam.gserviceaccount.com --key-file=gcp-artifact-writer.key
- Generate a token and authenticate to Docker:
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://<YOUR-GCP-REGION>-docker.pkg.dev
At this point you can use ImageSpec or Dockerfiles to build and push custom images to your Artifact Registry repo.
As part of the development process, Task Pods will pull the custom Image you defined in the workflow registration phase. For this to work, the default
Service Account in each project-domain
namespace will need to mount an imagePullSecret
.
- Generate a key for the Google Service Account that's been created with the permissions to read Images from Artifact Registry
gcloud iam service-accounts keys create gcp-artifact-reader.key --iam-account=flyte-gcp-flyteworkers@<YOUR-GCP-PROJECT_ID>.iam.gserviceaccount.com
- Create a Kubernetes secret in the
project-domain
namespace where you'll run your first workflow:
kubectl create secret docker-registry artifact-registry --docker-server=https://<YOUR-GCP-REGION>-docker.pkg.dev --docker-email=flyte-gcp-flyteworkers@<YOUR-GCP-PROJECT>.iam.gserviceaccount.com --docker-username=_json_key --docker-password="$(cat gcp-artifact-reader.key)" --namespace flytesnacks-development
- Edit your
default
Service Account:
kubectl edit sa default -n flytesnacks-development
- Add the
imagePullSecret
:
imagePullSecrets:
- name: artifact-registry
- Run the example in the docs to confirm.