Skip to content

Instantly share code, notes, and snippets.

@hasheddan
Created March 6, 2020 12:00
Show Gist options
  • Save hasheddan/98586b986ad4fbdf1658dc9f4204c4c0 to your computer and use it in GitHub Desktop.
Save hasheddan/98586b986ad4fbdf1658dc9f4204c4c0 to your computer and use it in GitHub Desktop.
  1. Install OpenFaaS using method of choice
  2. Install Crossplane with GCP provider
kubectl create namespace crossplane-system
helm repo add crossplane-alpha https://charts.crossplane.io/alpha

helm install crossplane --namespace crossplane-system crossplane-alpha/crossplane --set clusterStacks.gcp.deploy=true --set clusterStacks.gcp.version=master
  1. Create GCP Provider credentials
  2. Create CloudSQLInstanceClass (kubectl apply)
apiVersion: database.gcp.crossplane.io/v1beta1
kind: CloudSQLInstanceClass
metadata:
  name: cloudsqlinstancemysql-standard
  labels:
    app: tbs
specTemplate:
  writeConnectionSecretsToNamespace: crossplane-system
  forProvider:
    databaseVersion: MYSQL_5_6
    region: us-west2
    settings:
      tier: db-n1-standard-1
      dataDiskType: PD_SSD
      dataDiskSizeGb: 10
      ipConfiguration:
        ipv4Enabled: true
        authorizedNetworks:
          - value: "0.0.0.0/0"
  providerRef:
    name: gcp-provider
  reclaimPolicy: Delete
  1. Create MySQLInstance in openfaas-fn namespace (kubectl apply)
apiVersion: database.crossplane.io/v1alpha1
kind: MySQLInstance
metadata:
  name: mysql
  namespace: openfaas-fn
spec:
  classSelector:
    matchLabels:
      app: tbs
  writeConnectionSecretToRef:
    name: mysqlconn
  engineVersion: "5.6"
  1. Create OpenFaaS function in openfaas-fn namespace with secret mysqlconn defined in manifest
  2. Connect to MySQL database in function using secrets: username, password, endpoint (fields on the mysqlonn connection secret)

Some helpful examples:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment