kubernetes mariadb doesnt startt sql's from /docker-entrypoint-initdb.d

1/4/2022

pod logs:

2022-01-04 10:43:13+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.7.1+maria~focal started.
2022-01-04 10:43:14+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-01-04 10:43:14+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.7.1+maria~focal started.
2022-01-04 10:43:14 0 [Note] mariadbd (server 10.7.1-MariaDB-1:10.7.1+maria~focal) starting as process 1 ...
2022-01-04 10:43:14 0 [Note] mariadbd: Aria engine: starting recovery
recovered pages: 0% 19% 30% 42% 56% 67% 78% 89% 100% (0.0 seconds); tables to flush: 2 1 0
 (0.0 seconds);
2022-01-04 10:43:14 0 [Note] mariadbd: Aria engine: recovery done
2022-01-04 10:43:14 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-01-04 10:43:14 0 [Note] InnoDB: Using transactional memory
2022-01-04 10:43:14 0 [Note] InnoDB: Number of transaction pools: 1
2022-01-04 10:43:14 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
2022-01-04 10:43:14 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts)
2022-01-04 10:43:14 0 [Note] InnoDB: Using Linux native AIO
2022-01-04 10:43:14 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
2022-01-04 10:43:14 0 [Note] InnoDB: Completed initialization of buffer pool
2022-01-04 10:43:14 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=42161,42161
2022-01-04 10:43:14 0 [Note] InnoDB: Starting final batch to recover 106 pages from redo log.
2022-01-04 10:43:14 0 [Note] InnoDB: 128 rollback segments are active.
2022-01-04 10:43:14 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1"
2022-01-04 10:43:14 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-01-04 10:43:14 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-01-04 10:43:14 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-01-04 10:43:14 0 [Note] InnoDB: 10.7.1 started; log sequence number 419797; transaction id 328
2022-01-04 10:43:14 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2022-01-04 10:43:14 0 [Note] Plugin 'FEEDBACK' is disabled.
2022-01-04 10:43:14 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
2022-01-04 10:43:14 0 [Note] InnoDB: Buffer pool(s) load completed at 220104 10:43:14
2022-01-04 10:43:14 0 [Note] Server socket created on IP: '0.0.0.0'.
2022-01-04 10:43:14 0 [Note] Server socket created on IP: '::'.
2022-01-04 10:43:14 0 [Warning] 'proxies_priv' entry '@% root@mysql-686b8c87c-vm76x' ignored in --skip-name-resolve mode.
2022-01-04 10:43:14 0 [Note] mariadbd: ready for connections.
Version: '10.7.1-MariaDB-1:10.7.1+maria~focal'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution

but script presents on filesystem:

root@mysql-686b8c87c-vm76x:/# su mysql
$ id
uid=999(mysql) gid=999(mysql) groups=999(mysql)
$ head /docker-entrypoint-initdb.d/init.sql
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
CREATE DATABASE IF NOT EXISTS `login` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
USE `login`;

CREATE TABLE `apiqueue` (
  `id` int(64) UNSIGNED NOT NULL,
  `date` int(64) UNSIGNED NOT NULL,

and looks like entrypoint doest start:

time /usr/local/bin/docker-entrypoint.sh

real    0m0.007s
user    0m0.003s
sys     0m0.004s

yaml file:

kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - image: mariadb:10.7
          name: mysql
          env:
          - name: MARIADB_ROOT_PASSWORD
            value: testpassword
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
            - name: mysql-init-volume
              mountPath: /docker-entrypoint-initdb.d
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-volumeclaim
        - name: mysql-init-volume
          configMap:
            name: mysql-init-sql
            items:
            - key: createDB.sql
              path: init.sql
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mysql-volumeclaim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  type: ClusterIP
  ports:
    - port: 3306
  selector:
    app: mysql
---
apiVersion: v1
kind: Secret
metadata:
   name: mysql
type: Opaque
data:
  mysql-password: pass
  mysql-root-password: pass
  mysql-user: pass
  password: pass

also password from env.vars also doesnt work. And yes, i'll try remove pvc\pv before run. Also if i run entrypoint script manually it will stops immediatly, so probably this is some issue with entrypoint or idk

-- Dmitry Shumsky
initialization
kubernetes
mariadb

2 Answers

4/15/2022

I got the same issue, but after properly removing pvc and pv it worked.

-- Anel
Source: StackOverflow

4/18/2022

/docker-entrypoint-initdb.d is only executed if your data directory is empty. It's there for initialization and not every startup.

The pod logs you showed include Aria engine: starting recovery so the volume was already initialized. As such the /docker-entrypoint-initdb.d is ignored.

-- danblack
Source: StackOverflow