kubernetes mariadb fails to start on create database

5/19/2020

I am trying to deploy mariadb to my local kubernetes cluster. I'm building the image with the following Dockerfile:

FROM mariadb:10.2

ENV MYSQL_DATABASE=k8_demo \
    MYSQL_ROOT_PASSWORD=***** \
    MYSQL_ROOT_HOST=%

ADD mysql.cnf /etc/mysql/conf.d
ADD startup.sql /docker-entrypoint-initdb.d

EXPOSE 3306

startup.sql:

GRANT USAGE ON *.* TO 'root'@'%' IDENTIFIED BY '*****';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

FLUSH PRIVILEGES;

mysql.cnf:

[mysqld]
pid-file                = /var/run/mysqld/mysqld.pid
socket                  = /var/run/mysqld/mysqld.sock
# Where the database files are stored inside the container
datadir                 = /var/lib/mysql

# My application special configuration
max_allowed_packet          = 256M
sql-mode                    = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'

# Accept connections from any IP address
bind-address                = 0.0.0.0

Deploying the following deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysqldb
  labels:
    app: mysqldb
spec:
  replicas: 1
  template:
    metadata:
      name: mysqldb
      labels:
        app: mysqldb
    spec:
      containers:
        - name: mysqldb
          image: manuel/mysqldb
          ports:
            - containerPort: 3306
          env:
            - name: MYSQL_DATABASE
              valueFrom:
                configMapKeyRef:
                  name: mysqldb
                  key: db-name
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysqldb
                  key: db-password
          imagePullPolicy: Never
      restartPolicy: Always
  selector:
    matchLabels:
      app: mysqldb

---

apiVersion: v1
kind: Service
metadata:
  name: mysqldb
spec:
  selector:
    app: mysqldb
  ports:
    - port: 3307

The pod log as follows is not really helpful:

2020-05-19 15:13:17+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.2.31+maria~bionic started.
2020-05-19 15:13:17+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-05-19 15:13:17+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.2.31+maria~bionic started.
2020-05-19 15:13:18+00:00 [Note] [Entrypoint]: Initializing database files
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h  password 'new-password'
Alternatively you can run:
'/usr/bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
2020-05-19 15:13:20+00:00 [Note] [Entrypoint]: Database files initialized
2020-05-19 15:13:20+00:00 [Note] [Entrypoint]: Starting temporary server
2020-05-19 15:13:20+00:00 [Note] [Entrypoint]: Waiting for server startup
2020-05-19 15:13:20 139865539991232 [Note] mysqld (mysqld 10.2.31-MariaDB-1:10.2.31+maria~bionic) starting as process 124 ...
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Uses event mutexes
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Using Linux native AIO
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Number of pools: 1
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Using SSE2 crc32 instructions
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Completed initialization of buffer pool
2020-05-19 15:13:20 139864817927936 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Highest supported file format is Barracuda.
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: 128 out of 128 rollback segments are active.
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Creating shared tablespace for temporary tables
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: Waiting for purge to start
2020-05-19 15:13:20 139865539991232 [Note] InnoDB: 5.7.29 started; log sequence number 1615502
2020-05-19 15:13:20 139864578180864 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2020-05-19 15:13:20 139864578180864 [Note] InnoDB: Buffer pool(s) load completed at 200519 15:13:20
2020-05-19 15:13:20 139865539991232 [Note] Plugin 'FEEDBACK' is disabled.
2020-05-19 15:13:20 139865539991232 [Warning] 'user' entry 'root@mysqldb-5fcbfd4df8-qdpfq' ignored in --skip-name-resolve mode.
2020-05-19 15:13:20 139865539991232 [Warning] 'proxies_priv' entry '@% root@mysqldb-5fcbfd4df8-qdpfq' ignored in --skip-name-resolve mode.
2020-05-19 15:13:20 139865539991232 [Note] Reading of all Master_info entries succeeded
2020-05-19 15:13:20 139865539991232 [Note] Added new Master_info '' to hash table
2020-05-19 15:13:20 139865539991232 [Note] mysqld: ready for connections.
Version: '10.2.31-MariaDB-1:10.2.31+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  mariadb.org binary distribution
2020-05-19 15:13:21+00:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
2020-05-19 15:13:24 139864904218368 [Warning] 'proxies_priv' entry '@% root@mysqldb-5fcbfd4df8-qdpfq' ignored in --skip-name-resolve mode.
2020-05-19 15:13:24+00:00 [Note] [Entrypoint]: Creating database mysqldb
mysql: unknown option '--"'

I'm now looking into https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/ since it might have something to do with the volume... https://github.com/docker-library/mariadb/issues/76

What option is it referring to? Is there a way to get more information, since opening a shell is not possible since the container keeps crashing.

edit: added content of startup.sql and mysql.cnf edit: typo

-- Manuel Waltschek
docker
kubernetes
mariadb

0 Answers