Using a MariaDB service
The YAML code below creates two objects: a VSHNMariaDB
instance and a pod accessing it to show information about the instance.
The latter references the mariadb-creds-connection
secret that will contain the access keys required to connect to the instance.
apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNMariaDB
metadata:
name: my-mariadb-example
namespace: my-namespace
spec:
parameters:
service:
version: "11.2"
writeConnectionSecretToRef:
name: mariadb-creds-connection (1)
---
apiVersion: v1
kind: Pod
metadata:
name: mariadb-client
spec:
containers:
- name: mariadb
image: mariadb:11.2
command:
- /bin/sh
- -c
args:
- mariadb --host=$MARIADB_HOST --user=$MARIADB_USERNAME --port=$MARIADB_PORT --password=$MARIADB_PASSWORD --ssl-verify-server-cert --ssl-ca=/etc/mariadb-tls/ca.crt -e 'SHOW DATABASES' (3)
volumeMounts:
- name: mariadb-tls-secrets (4)
readOnly: true
mountPath: "/etc/mariadb-tls"
envFrom:
- secretRef:
name: mariadb-creds-connection (2)
volumes:
- name: mariadb-tls-secrets (4)
secret:
defaultMode: 0600
secretName: mariadb-creds-connection (2)
restartPolicy: Never
yaml
1 | The operator will create a secret with the access keys to connect to the instance. |
2 | The pod and the volume will use the new secret. |
3 | Uses mariadb to print all existing databases to stdout. |
4 | Mount the secret with the credentials to the pod, for TLS support (enabled by default) |
Debug the service
To check the status and potential issues or errors in the service, check the status
field of the new object:
$ oc describe vshnmariadb.vshn.appcat.vshn.io my-mariadb-example [...] Status: Conditions: Last Transition Time: 2023-02-17T23:25:57Z Reason: ReconcileSuccess Status: True Type: Synced Last Transition Time: 2023-02-17T23:26:07Z Reason: Available Status: True Type: Ready Connection Details: Last Published Time: 2023-02-17T23:26:07Z Local CA Debug: Last Transition Time: 2023-02-17T23:25:59Z Reason: Available Status: True Type: Ready Last Transition Time: 2023-02-17T23:25:58Z Reason: ReconcileSuccess Status: True Type: Synced Namespace Debug: Last Transition Time: 2023-02-17T23:25:59Z Reason: Available Status: True Type: Ready Last Transition Time: 2023-02-17T23:25:58Z Reason: ReconcileSuccess Status: True Type: Synced
bash