Skip to content

Instantly share code, notes, and snippets.

@paulomach
Last active April 17, 2023 11:02
Show Gist options
  • Select an option

  • Save paulomach/83c31b8691f464eaf0c8cbcc685068b1 to your computer and use it in GitHub Desktop.

Select an option

Save paulomach/83c31b8691f464eaf0c8cbcc685068b1 to your computer and use it in GitHub Desktop.
Kubecon Operator Day 2023

Data on kubernetes with the MySQL charmed operator

Steps to reproduce the demos at the presentation, using mysql-k8s, mysql-router-k8s, tls-certificates and s3-integrator operators.

High Availability

We assume a kubernetes juju controller already in place case not, follow the instructions at microk8s in juju

# add a new juju model
juju add-model operator-day

# deploy the MySQL operator from edge channel
juju deploy mysql-k8s --channel edge --trust

# Take a look at the available actions for the operator
juju actions mysql-k8s

# Check cluster status by calling action
juju run-action mysql-k8s/0 get-cluster-status --wait

# Now, scale out to a fault tolerant cluster (3 instances)
juju scale-application mysql-k8s 3

# Check cluster status again to validate the three node cluster
juju run-action mysql-k8s/0 get-cluster-status --wait

# Let's try to kill the primary instance of the cluster
# **Note** the juju model name is the k8s namespace
kubectl -n operador-day delete pod/mysql-k8s-0 

# While the cluster recover, let's retrieve dabatase root user password
# we are using unit 1 since unit 0 may not be available yet
juju run-action mysql-k8s/1 get-password user=root --wait

Router and test application

# Deployment of mysql-router and test application
juju deploy mysql-router-k8s  --channel edge
juju deploy mysql-test-app app --channel edge

# Relate mysql <-> mysql-router <-> test-app
juju relate mysql-router-k8s mysql-k8s
juju relate app mysql-router-k8s

# The test application start a continuous writes after relations are settled
# the router ip can be found on the output of `juju status`
mysqlsh --sql root:<password>@<mysql-router-ip>:6446 # or 6447 for read-only/replicas access

To check the continuous writes, try the query:

select max(number) from continuous_writes_database.data; 

and to stop the writes:

juju run-action app/0 stop-continuous-writes --wait

Encryption

Validate default encryption

mysqlsh --sql root:<password>@<any-mysql-unit>:3306

and on the mysqlsh prompt run \status

Repeat the procedure with:

mysqlsh --sql root:<password>@<any-mysql-unit>:3306 --ssl-mode=DISABLED
# connection is still possible

Deploy tls-certificates-operator:

juju deploy tls-certificates-operator tls \
  --config generate-self-signed-certificates=true \
  --config ca-common-name="My CA"
# and relate
juju relate tls mysql-k8s

mysqlsh --sql root:<password>@<any-mysql-unit>:3306 --ssl-mode=DISABLED
# connection is not possible

Backups & Restores

# For backups, let's use a new model.
juju add-model dev

# Deploy single node cluster
juju deploy -n 1 mysql-k8s --series=jammy --channel=latest/edge

# Feploy S3 integrator setting configuratuion
juju deploy -n 1 s3-integrator --series=jammy --channel=latest/edge --config bucket=<bucket> --config path=<path>

# Run sync credentials action
juju run-action s3-integrator/0 --wait --format yaml sync-s3-credentials access-key=<access-key> secret-key=<secret-key>

# and relate apps
juju relate mysql-k8s s3-integrator

# List any existing backups for the given account
juju run-action mysql-k8s/0 --wait --format yaml list-backups

# Run the backup
juju run-action mysql-k8s/0 --wait --format yaml create-backup

Restore

# Rotate user credentials
juju run-action mysql-k8s/0 --wait --format yaml set-password username=root password=<password>
juju run-action mysql-k8s/0 --wait --format yaml set-password username=serverconfig password=<password>
juju run-action mysql-k8s/0 --wait --format yaml set-password username=clusteradmin password=<password>

# Restore a given backup from S3
juju run-action mysql-k8s/0 --wait --format yaml restore backup-id=<id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment