- Install OpenFaaS using method of choice
- 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
- Create GCP Provider credentials
- 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
- 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"
- Create OpenFaaS function in
openfaas-fn
namespace with secretmysqlconn
defined in manifest - Connect to MySQL database in function using secrets:
username
,password
,endpoint
(fields on themysqlonn
connection secret)
Some helpful examples: