如何在Kubernetes中使用示例数据启动mysql容器?

时间:2019-07-13 16:07:21

标签: mysql kubernetes google-kubernetes-engine dump

我需要在Kubernetes中使用数据库,模式和示例数据启动MySQL容器。

我尝试在Kubernetes yaml中使用参数“ command”,但是在执行时,数据库仍未启动。

        - 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"

2 个答案:

答案 0 :(得分:0)

您可以先创建mysql的容器,然后再以这种方式导入mysql的数据。

您可以创建pvc卷并启动没有任何数据库的黑色容器。 您可以使用命令exec将sql while和数据导入数据库,这将创建数据库并在容器内采样数据。

启动容器,并以exec模式进入容器并创建数据库,然后运行此命令

Traceback (most recent call last):
  File "threaded_crawler_with_queue.py", line 49, in <module>
    num_procs=par_args.num_procs, max_threads=par_args.max_threads)
  File "threaded_crawler_with_queue.py", line 22, in mp_threaded_crawler
    proc.start()
  File "C:\Users\iR9\Anaconda3\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Users\iR9\Anaconda3\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\iR9\Anaconda3\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Users\iR9\Anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Users\iR9\Anaconda3\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle _thread.lock objects

C:\Users\iR9\Desktop\wswp\code>Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\iR9\Anaconda3\lib\multiprocessing\spawn.py", line 99, in spawn_main
    new_handle = reduction.steal_handle(parent_pid, pipe_handle)
  File "C:\Users\iR9\Anaconda3\lib\multiprocessing\reduction.py", line 82, in steal_handle
    _winapi.PROCESS_DUP_HANDLE, False, source_pid)
OSError: [WinError 87] The parameter is incorrect

答案 1 :(得分:0)

解决了

      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