I wanted to create a MySQL container in Kubernetes with default disabled strict mode. I know the way of how to disable strict mode in docker. I tried to use the same way in Kubernetes, but it shows an errors log.
docker
docker container run -t -d --name hello-wordl mysql --sql-mode=""
kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-db
labels:
app: db
spec:
selector:
matchLabels:
app: db
template:
metadata:
name: my-db
labels:
app: db
spec:
containers:
- name: my-db
image: mariadb
imagePullPolicy: Always
args: ["--sql-mode=\"\""]
error:
2021-10-29 08:20:57 00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.2.40 maria~bionic started. 2021-10-29 08:20:57 00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config command was: mysqld --sql-mode="" --verbose --help --log-bin-index=/tmp/tmp.i8yL5kgKoq 2021-10-29 8:20:57 140254859638464 [ERROR] mysqld: Error while setting value '""' to 'sql_mode'
CodePudding user response:
Based on the error you're getting, it is reading the double quotes as value to sql_mode. You should omit the escaped double-quotes.
args: ["--sql-mode="]
CodePudding user response:
It seems you have to use a configmap
for this.
Configmap manifest:
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
labels:
app: mysql
data:
my.cnf: |-
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
max_connections = 2000
secure_file_priv=/var/lib/mysql
sql_mode=STRICT_TRANS_TABLES
Deployment Manifest : in Volume section
volumeMounts:
- name: data
mountPath: /var/lib/mysql
- name: config
mountPath: /etc/mysql/conf.d/my.cnf
subPath: my.cnf
volumes:
- name: config
configMap:
name: mysql-config
This will replace your default my.conf
in MySQL container, if you need to set more variables, better to include them in the configmap
For more detailed answer