Error from server (RequestEntityTooLarge): Request entity too large: limit is 3145728 while creating a configMap

5/29/2020

I use configMap to feed the init.sql script to initialise my Mysql container in the Kubernetes pod. While that works for most cases I am struggling to convert a larger init.sql file which is 12.2 MB. I use the following in deployment.yaml to mount the configMap.

volumeMounts:
- name: init-volume
  mountPath: /docker-entrypoint-initdb.d
volumes:
- name: init-volume
  configMap:
    defaultMode: 420
    name: init-volume

The command I use to create the configMap

kubectl create configMap init-volume --from-file=init.sql

I get the error

Error from server (RequestEntityTooLarge): Request entity too large: limit is 3145728

How can I increase this limit/or any other alternate to initialise my database?

-- Vishakha Lall
containers
kubernetes
mysql

1 Answer

5/30/2020

How can I increase this limit/or any other alternate to initialise my database?

The .d nomenclature in that path means it will load all files found therein, so the solution is to chop up the init.sql into smaller chunks, name them so that they apply in the right order when viewed with /bin/ls -1, and stick each one into a configmap:

i=1
for fn in *.sql; do
   kubectl create configmap init-sql-$i --from-file="$fn"
   i=$(( i + 1 ))
done

then volume mount them into the directory

volumeMounts:
- name: init-file-1
  mountPath: /docker-entrypoint-initdb.d/file-1.sql
- name: init-file-2
  mountPath: /docker-entrypoint-initdb.d/file-2.sql
# and so forth
-- mdaniel
Source: StackOverflow