import mysql data to kubernetes pod

10/20/2016

Does anyone know how to import the data inside my dump.sql file to a kubernetes pod either;

Directly,same way as you dealing with docker containers:

docker exec -i container_name mysql -uroot --password=secret database < Dump.sql

Or using the data stored in an existing docker container volume and pass it to the pod .

-- montatich
containers
docker
google-kubernetes-engine
kubernetes
mysql

2 Answers

6/15/2018

Just if other people are searching for this :

kubectl -n namespace exec -i my_sql_pod_name -- mysql -u user -ppassword < my_local_dump.sql
-- Camk_lcbr
Source: StackOverflow

10/22/2016

To answer your specific question:

You can kubectl exec into your container in order to run commands inside it. You may need to first ensure that the container has access to the file, by perhaps storing it in a location that the cluster can access (network?) and then using wget/curl within the container to make it available. One may even open up an interactive session with kubectl exec.

However, the ways to do this in increasing measure of generality would be:

  1. Create a service that lets you access the mysql instance running on the pod from outside the cluster and connect your local mysql client to it.

  2. If you are executing this initialization operation every time such a mysql pod is being started, it could be stored on a persistent volume and you could execute the script within your pod when you start up.

  3. If you have several pieces of data that you typically need to copy over when starting the pod, look at init containers for fetching that data.

-- Anirudh Ramanathan
Source: StackOverflow