You can use mysql-client to send some data to the leader, mysql-0.mysql by running the following command.
kubectl -n mysql run mysql-client --image=mysql:5.7 -i --rm --restart=Never --\
mysql -h mysql-0.mysql <<EOF
CREATE DATABASE test;
CREATE TABLE test.messages (message VARCHAR(250));
INSERT INTO test.messages VALUES ('hello, from mysql-client');
EOF
Run the following to test follower (mysql-read) received the data.
kubectl -n mysql run mysql-client --image=mysql:5.7 -it --rm --restart=Never --\
mysql -h mysql-read -e "SELECT * FROM test.messages"
The output should look like this.
To test load balancing across followers, run the following command.
kubectl -n mysql run mysql-client-loop --image=mysql:5.7 -i -t --rm --restart=Never --\
bash -ic "while sleep 1; do mysql -h mysql-read -e 'SELECT @@server_id,NOW()'; done"
Each MySQL instance is assigned a unique identifier, and it can be retrieved using @@server_id
. It will print the server id serving the request and the timestamp.
Leave this open in a separate window while you test failure in the next section.