vitalsource / proxysql-docker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ProxySQL Container

To build this container, run:

docker build -t my-alpine-proxysql-build .

To run this container interactively, build and run with an entrypoint of ash:

docker build -t my-alpine-proxysql-build .
docker run -it --rm --entrypoint ash my-alpine-proxysql-build

To bootstrap this container with the proper replication hostgroup configuration, a bit of hackery is needed until v1.2.2 is released.

The process involves running a donor container, setting the replication hostgroup config as you want it, then copying the sqlite3 database file out of the container then modifying the tables so we can use it as a seed database for the actual runtime container.

First, run your donor container:

docker run --name proxysql_donor -d -p 6032:6032 perconalab/proxysql

Next, connect to the admin interface and set up your hostgroup configuration:

INSERT INTO mysql_replication_hostgroups VALUES (0,1);
SAVE MYSQL SERVERS TO DISK;

Then, copy the sqlite3 database file out of the running donor container:

docker cp `docker ps | grep proxysql_donor | awk '{print $1}'`:/var/lib/proxysql/proxysql.db .

Finally, use sqlite3 to drop all tables except for the mysql_replication_hostgroups table:

sqlite3 proxysql.db

drop table global_variables;
drop table mysql_collations;
drop table mysql_query_rules;
drop table mysql_servers;
drop table mysql_users;
drop table scheduler;
.quit

Once you've modified the proxysql.db as noted above, it can be used as a seed for the running configuration that is created when starting the container generated by this repository's Dockerfile.

The configuration included herein was used for testing purposes, and you would use this in a production environment with either a bind mounted proxysql.cnf (-v /path/to/your/proxysql.cnf:/proxysql/proxysql.cnf) or a k8s Secret that has been created from a valid configuration file, then mounted as a volume at /proxysql/proxysql.cnf in your pod.

A sample kubernetes deployment yaml is included in this repository. In kubernetes the configuration can be driven by a Secret or ConfigMap to allow flexible configuration options, versus hard-coding a proxysql.cnf into the container. See the example deployment yaml for usage, replacing my-alpine-proxysql-build with the name of your proxysql container. To create a consumable secret, generate a proxysql configuration file, then run ./config-to-secret.sh <config-file> and the script will generate a file named proxysql-config-secret.yaml which can be imported to kubernetes with kubectl create -f proxysql-config-secret.yaml.

About


Languages

Language:Shell 100.0%