Here’s how I did this for the sake of sharing answering my own post.
I started by inspecting the CRD using kubectl explain
Explain ksqldb.spec and ksql.spec.mountedVolumes
ksqldb crd has a section in the spec for mountedVolumes that will allow us to mount our sql file.
kubectl explain KsqlDB.spec
KIND: KsqlDB
VERSION: platform.confluent.io/v1beta1
RESOURCE: spec <Object>
DESCRIPTION:
spec defines the desired state of the ksqlDB cluster.
FIELDS:
...
mountedVolumes <Object>
mountedVolumes list the custom volumes that need to be mounted into the
underlying statefulset. A change to this setting will roll the cluster.
...
Next take a look at the mounted volumes section
kubectl explain KsqlDB.spec.mountedVolumes
KIND: KsqlDB
VERSION: platform.confluent.io/v1beta1
RESOURCE: mountedVolumes <Object>
DESCRIPTION:
mountedVolumes list the custom volumes that need to be mounted into the
underlying statefulset. A change to this setting will roll the cluster.
FIELDS:
volumeMounts <[]Object> -required-
volumeMounts specify the list of volume mounts for the pods in the
statefulset.
volumes <[]Object> -required-
volumes specify the list of volumes that can be mounted into the pods of
statefulset.
We have the option to mount a volume in the ksqldb pod. So we can create a config map from our sql file and mount it to the sqldb pod. I’m building a helm chart to deploy but it would work as yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: ksqldb-ksql-queries-configmap
namespace: {{ .Values.namespace }}
data:
{{- $files := .Files }}
{{- range tuple "queries.sql" }}
{{ . }}: |-
{{ $files.Get . | indent 4 }}
{{- end }}
Now I can configure my ksql template to include the config map
apiVersion: platform.confluent.io/v1beta1
kind: KsqlDB
metadata:
name: ksqldb
namespace: {{ .Values.namespace }}
spec:
replicas: {{ .Values.ksqldb.replicas }}
image:
application: confluentinc/cp-ksqldb-server:{{ .Values.version }}
init: confluentinc/confluent-init-container:2.3.0
configOverrides:
server:
- access.control.allow.origin=*
- access.control.allow.methods=GET,POST,HEAD
- access.control.allow.headers=X-Requested-With,Content-Type,Accept,Origin,Authorization
- ksql.queries.file=/etc/ksql/queries/queries.sql
dataVolumeCapacity: 10Gi
mountedVolumes:
volumeMounts:
- name: ksql-queries
mountPath: /etc/ksql/queries
volumes:
- name: ksql-queries
configMap:
name: ksqldb-ksql-queries-configmap
Note the config override - ksql.queries.file=/etc/ksql/queries/queries.sql
that tells ksqldb to use the file provided in the volume to set initial queries.