With this option you can provide the script or many script as you required in three different ways:
Create the file sgcluster-with-raw-script.yaml
and apply the following YAML file:
apiVersion: stackgres.io/v1
kind: SGCluster
metadata:
name: stackgres
spec:
initialData:
scripts:
- name: create-my-database
script: |
create database my_db owner postgres;
and deploy to Kubernetes:
kubectl apply -f sgcluster-with-raw-script.yaml
Note: Avoid this method to create sensitive data like user and passwords.
Using this method you need to create the secret first:
kubectl create secret generic database-user \
--from-literal=create-user.sql="create user demo password 'demo'"
Then add the reference in the initialData section:
Create the YAML file sgcluster-with-secret-script.yaml
:
apiVersion: stackgres.io/v1
kind: SGCluster
metadata:
name: stackgres
spec:
initialData:
scripts:
- name: create-database-user
scriptFrom:
secretKeyRef:
name: database-user
key: create-user.sql
and deploy to Kubernetes:
kubectl apply -f sgcluster-with-secret-script.yaml
First create a configmap:
kubectl create configmap init-tables \
--from-literal=create-init-tables.sql="create table company(id integer, name char(50));"
Note: To load more complex or larger queries create the configmap from your sql files.
Create the YAML file sgcluster-with-script-from-configmap.yaml
apiVersion: stackgres.io/v1
kind: SGCluster
metadata:
name: stackgres
spec:
initialData:
scripts:
- name: create-database-user
scriptFrom:
configMapKeyRef:
name: init-tables
key: create-init-tables.sql
and deploy to Kubernetes:
kubectl apply -f sgcluster-with-script-from-configmap.yaml