Search code examples
mysqlkubernetesgoogle-kubernetes-enginedump

How to start a mysql container in Kubernetes with sample data?


I need to start a MySQL container in Kubernetes with a database and a schema and sample data.

I tried to use the parameter "command" in the Kubernetes yaml, but at the time of execution, the db is still not started.

        - image: mysql:5.7.24
          name: database
          command:
            [
              '/usr/bin/mysql -u root -e "CREATE DATABASE IF NOT EXISTS mydbname"',
            ]
          env:
            - name: MYSQL_ALLOW_EMPTY_PASSWORD
              value: "1"

Solution

  • Solved adding

          volumeMounts:
            - name: initdb
              mountPath: /docker-entrypoint-initdb.d
    
    ...
      volumes:
        - name: initdb
          configMap:
            name: initdb-config
    
    ...
    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: initdb-config
    data:
      initdb.sql: |
          mysqlquery