MySQL Docker Image: initialized with env variable of K8S Secret - mysql

When i tried to deploy with K8S using env variable for Root Password (MYSQL_ROOT_PASSWORD , a variable used in docker-entrypoint.sh) such as
kind: Deployment
#omitted...
spec:
containers:
#omitted...
env:
- name: MYSQL_ROOT_PASSWORD
value: my-secret-passw
it seems that the deployment with kubectl apply -k is working. Of course, this insecure deployment. MySql initialization works and everything is as expected.
So i tried to create a secret and retrieving the value from that secret, such that
kind: Deployment
#omitted...
spec:
containers:
#omitted...
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
key: MYSQL_ROOT_PASSWORD
name: mysql-root-password
mysql initialization is not working. And i have no idea what the heck is going wrong. The kubectl logs or stdout from the container is the following (bear in mind that using literal root pass didn't return result like this):
[MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
[Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/sql-script.sql
mysql: [ERROR] unknown option '-- "'.
When checking the docker image source code, it seems there is no string about "unknown option" (see here the github and i am using mysql 8.0. It seems it's coming out of mysql itself.
So why is it that when using literal value on k8S env variable (which is not safe!) working but not with reading from secret?

Seems like version 8.0 is broken or missing something because it cannot see the password.
I'm not an expert in this field so maybe someone else can add some more details.
2020-02-07T16:09:06.648827Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-02-07T16:09:06.649084Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 44
2020-02-07T16:09:10.821145Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-02-07 16:09:14+00:00 [Note] [Entrypoint]: Database files initialized
2020-02-07 16:09:14+00:00 [Note] [Entrypoint]: Starting temporary server
2020-02-07T16:09:14.823453Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-02-07T16:09:14.823582Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 94
2020-02-07T16:09:15.631008Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-02-07T16:09:15.635649Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-02-07T16:09:15.655790Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2020-02-07 16:09:15+00:00 [Note] [Entrypoint]: Temporary server started.
2020-02-07T16:09:15.740600Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2020-02-07 16:09:19+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-02-07T16:09:19.476870Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
I've tested the image 5.6 from official mysql repository and it's seems to work perfectly fine.
I've run whole MySQL + WordPress deployment using the Tutorial on kubernetes.io which I do recommend.
I've created the secret manually, using:
kubectl create secret generic mysql-pass --from-literal=password=test
Looks like there is an issue open for problem similar to this "Unable to start server" on Amazon Linux AMI (works with 5.7) #628.

After sometime, i realized that the problem is not with the Secret of K8S. I accidentally changed my password into string of chars without Special characters, and that solved it! From the post, you see that the character -- was read as an input of the next process (dang it, i am giving away my pass! nah, changed it already).
So anyone of you with the same problem (with mysql), please consider choosing a secret with no-special-characters password. Long password with combination of numbers/case-sensitive could be strong enough, especially if you paper and pencil!

Related

The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it inside the Kubernetes Pod

I am running Minikube version 1.20 w/ KVM2 as a VM driver inside my Ubuntu 20.04 LTS. When I am trying to deploy SQL inside my local Kubernetes cluster. It keeps restarting with the below pod logs error
2023-01-17 07:15:17+00:00 [Note] [Entrypoint]: Initializing database files
2023-01-17T07:15:17.153897Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-01-17T07:15:17.154020Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2023-01-17T07:15:17.154036Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 42
2023-01-17T07:15:17.155532Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2023-01-17T07:15:17.155536Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2023-01-17T07:15:17.155571Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-01-17T07:15:17.155647Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL.
I am trying to use mysql:8 image and mountPath: /var/lib/mysql.
Seems like the volume contains something from the error. You can try to delete the pod and related resources (e.g. PVC, service, etc), delete the data directory and any files within it. After, create the pod again and make sure that the data directory is empty and not being used by any other pod or service and make sure that the mountPath: /var/lib/mysql should be empty before the pod creation.
If you tried multiple times i would suggest trying deleting everything first and applying changes again PV and PVC. There could be changes in PVC, PVC old files exist which causes issues.
Try deploying everything again and also check MySQL image.
You can refer this for more info : https://stackoverflow.com/a/70800469/5525824

Access denied for user 'root'#'localhost' in the mysql docker

Running a docker mysql container in the following command
docker run -it --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
then docker creates a running mysql container with logs as
2020-07-23 09:39:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
2020-07-23 09:39:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-07-23 09:39:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
2020-07-23 09:39:20+00:00 [Note] [Entrypoint]: Initializing database files
2020-07-23T09:39:20.408751Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-07-23T09:39:20.408909Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 42
2020-07-23T09:39:20.424771Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-23T09:39:22.342488Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-23T09:39:26.473394Z 6 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-07-23 09:39:35+00:00 [Note] [Entrypoint]: Database files initialized
2020-07-23 09:39:35+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld will log errors to /var/lib/mysql/da5f3f1ae045.err
mysqld is running as pid 91
2020-07-23 09:39:37+00:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2020-07-23 09:39:56+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-07-23 09:39:59+00:00 [Note] [Entrypoint]: Temporary server stopped
2020-07-23 09:39:59+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2020-07-23T09:39:59.908211Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-07-23T09:39:59.910343Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
2020-07-23T09:39:59.945124Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-23T09:40:00.579927Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-23T09:40:00.969050Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2020-07-23T09:40:01.137873Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-07-23T09:40:01.138424Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-07-23T09:40:01.145079Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-07-23T09:40:01.233430Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
Trying to access the container with
mysql -h localhost -u root -p
it asks for the password, using 123456 as the password fails; using empty password also fails.
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
docker exec -it mysql mysql -uroot -p, then a prompt is out to input the password with 123456, then It can successfully get access to the mysql command line. however why I can't use tableplus
From the comment above it's verified that you are able to access the mysql server inside the container, so the issue with tableplus not the container root password.
Just publish the port and it should work,
docker run -it -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
Also, it seems like tableplus connecting with host MySQL instead of container one as container did not publish the port in your case so it trying to connect somewhere else.
It might be that this MySQL installation uses authentication mechanisms of the operating system. Instead of the root passowrd.
To test if that's the case, execute the following command:
sudo mysql -u root
It will ask you for your operating system privileged password, not the MySQL root password (which might be unset).
After you get in, you can add new users, as usual and as described in MySQL manual and tutorials.
Also, you might want try the instructions mentioned here:
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
See section "B.4.3.2.3 Resetting the Root Password: Generic Instructions".
Quoting it below (and cleaned up a bit), in case if the website is not reachable:
Stop the MySQL server if necessary, then restart it with the
--skip-grant-tables option (see How to start MySQL with --skip-grant-tables? for some ways how to do it)
Connect to the MySQL server using the mysql client; no password is
necessary because the server was started with --skip-grant-tables:
shell> mysql
In the mysql client, tell the server to reload the grant
tables so that account-management statements work:
mysql> FLUSH PRIVILEGES;
Then change the 'root'#'localhost' account
password. Replace the password with the password that you want to use.
To change the password for a root account with a different host name
part, modify the instructions to use that host name.
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
You
should now be able to connect to the MySQL server as root using the
new password. Stop the server and restart it normally (without the
--skip-grant-tables option).
I had the same issue and i fixed it replacing localhost with the private ip:
mysql -u root -p -h 192.168.10.4

MySQL server dies or doesn't start on Mac OS Catalina 10.15.4

I installed the latest version of MySQL mysql-8.0.20-macos10.15-x86_64
When I start the server, it doesn't start. When I look into logs I see the following message:
sudo tail -n10 /usr/local/mysql/data/MacBook-Pro.local.err
2020-04-29T19:14:15.781011Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/tmp/mysqlx.sock' bind-address: '::' port: 33060
2020-04-29T19:14:15.875568Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-04-29T19:14:15.881149Z 0 [ERROR] [MY-000067] [Server] unknown variable 'query_cache_size=32M'.
2020-04-29T19:14:15.882207Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-04-29T19:14:16.820509Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.20) MySQL Community Server - GPL.
I cannot find where query_cache_size is coming from and I didn't set it.
This is the list of files/folder in MySQL folder:
LICENSE bin docs keyring man support-files
README data include lib share
I found the fix.
Documenting my troubleshooting/fix steps, so that it can save someone else hours of debugging.
Located the my.cnf file /private/etc/my.cnf, and noticed that a lot of configs were still conflicting as I was disabling them one by one. So, I simply renamed my.cnf to my.cnf.bak i.e. forcing MySQL to create a brand new file (now god knows where it created new one, that is a mystery for some other day :) )
Started the server using sudo /usr/local/mysql/support-files/mysql.server start
The server was still not starting and it was erroring with Unable to lock ./ibdata1 error: 35
So, I killed the ghost mysql process ps aux | grep mysql and kill <process-name>
Yay! server started running.

I am getting wordpress mysql connection error using docker

I created two docker containers using the commands below.
docker pull wordpress
docker pull mysql
docker run --name wordpress_database -e MYSQL_ROOT_PASSWORD=password -d mysql
docker run --name wordpress_website --link wordpress_database:mysql -p 8080:80 -d wordpress
When I looked at the later logs, I encountered an error. Logs are below.
How do I prevent these errors?
docker logs wordpress_website
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
[15-Apr-2020 12:08:38 UTC] PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
[15-Apr-2020 12:08:38 UTC] PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
MySQL Connection Error: (2054) The server requested authentication method unknown to the client
[15-Apr-2020 12:08:41 UTC] PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
[15-Apr-2020 12:08:41 UTC] PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
WARNING: unable to establish a database connection to 'mysql'
continuing anyways (which might have unexpected results)
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[Wed Apr 15 12:09:06.057462 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.16 configured -- resuming normal operations
[Wed Apr 15 12:09:06.057505 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
docker logs wordpress_database
2020-04-15 12:07:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Initializing database files
2020-04-15T12:07:20.102858Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-15T12:07:20.102959Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 43
2020-04-15T12:07:23.537919Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-04-15 12:07:27+00:00 [Note] [Entrypoint]: Database files initialized
2020-04-15 12:07:27+00:00 [Note] [Entrypoint]: Starting temporary server
2020-04-15T12:07:27.774674Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-15T12:07:27.774765Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 93
2020-04-15T12:07:28.389657Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-04-15T12:07:28.397651Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-04-15T12:07:28.421413Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2020-04-15 12:07:28+00:00 [Note] [Entrypoint]: Temporary server started.
2020-04-15T12:07:28.457791Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2020-04-15 12:07:30+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-04-15T12:07:30.812504Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
2020-04-15T12:07:32.529079Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.
2020-04-15 12:07:32+00:00 [Note] [Entrypoint]: Temporary server stopped
2020-04-15 12:07:32+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2020-04-15T12:07:33.133835Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-15T12:07:33.133938Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 1
2020-04-15T12:07:33.647310Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-04-15T12:07:33.652627Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-04-15T12:07:33.673452Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2020-04-15T12:07:33.812073Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
localhost:8080
Error establishing a database connection
You need to publish ports to the host interface for MySQL container. Use this command to start the MySQL docker container:
docker run --name wordpress_database -e MYSQL_ROOT_PASSWORD=password -d -p 3306:3306 mysql
Read this for more details regarding publishing ports in a docker container.

Can't run a MySQL slave instance on GKE

I have a MySQL service running on Google Kubernetes Engine configured with Master-Slave replication strategy. Unfortunately up until now only I am only managed to have the master (mysql-0) instance running. Slave instances (mysql-n) always stuck on CrashLoopBackOff.
Current pods:
When I check the log for mysql-1 instance, the following lines printed:
2020-01-08 08:11:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2020-01-08 08:11:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-01-08 08:11:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2020-01-08 08:11:20+00:00 [Note] [Entrypoint]: Initializing database files
2020-01-08T08:11:20.787668Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-01-08T08:11:20.787780Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.18) initializing of server in progress as process 45
2020-01-08T08:11:20.789731Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2020-01-08T08:11:20.789739Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2020-01-08T08:11:20.790259Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-01-08T08:11:20.791368Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.18) MySQL Community Server - GPL.
On the master MySQL Instance (mysql-0), the following lines printed:
2020-01-08 08:08:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2020-01-08 08:08:03+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-01-08 08:08:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2020-01-08T08:08:03.605134Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-01-08T08:08:03.605280Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 1
2020-01-08T08:08:05.939722Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-01-08T08:08:05.945787Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-01-08T08:08:06.069048Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.18' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2020-01-08T08:08:06.303012Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
The key difference between the two logs is, on the slave instance, the line Initializing database files are printed, indicating mysqld attempted to initalize already existing mysql data directory (/var/lib/mysql) whereas it doesn't happen when the master instance initializes.
I was following this kubernetes guide but it doesn't work on MySQL version 8. So I modify the StatefulSet deployment. Here is the yaml snippet
Anybody has idea on how to solve this problem? Much appreciated :)
UPDATE:
Solution provided by #BinaryBullet actually works with some changes down the line to enable multiple slaves replication. This yaml file is the end result.
I could see this is the issue with your volumemount, as you have single VolumeClaimTemplate for both master and slave mysql-bin files, schemas, ib_buffer_pool, etc all other mysql related files are conflicting with each other and trying to save at the same location. Due to this one of your db instance is failing, i.e. which ever starting later is failing, in your case slave db.
This could be avoided by adding separate PV and PVC for your master and slave.
Addition of something like this to your statefulset
volumeClaimTemplates:
- metadata:
name: slave-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
And volumemount for slave pod is something like this
volumeMounts:
- name: slave-data
mountPath: /var/lib/mysql
subPath: mysql
- name: conf
mountPath: /etc/mysql/conf.d
But make sure you have a separate Persistent Volume for your slave as well. To which all your slave mysql-bin files, ib_buffer_pool, schemas, etc mysql related files get saved in a different location from master.
Hope this helps.