Kubernetes 容器命令

Kubernetes Container Command

我正在 Kubernetes 中使用 Neo4j。 对于展示,我想用初始数据填充 Pods 中的 Neo4j,我可以使用密码文件来完成,我在 /bin 文件夹中使用密码-shell. 所以基本上我启动容器和 运行 cat bin/initialData.cypher | bin/cypher-shell。 我已经通过 运行 在 kubectl exec -it <pod> /bin/bash bash 中验证它是否有效。 但是,无论我如何尝试映射到 spec.container.command,它都会失败。 目前我最好的猜测是

spec:
  containers:
    command:
        - /bin/bash
        - -c
        - |
          cd bin
          ls
          cat initialData.cypher | cypher-shell

这是行不通的。它正确显示 ls 但随后抛出 connection refused,我不知道它来自哪里。

编辑:已更新

Exec 似乎是处理此问题的更好方法,但您通常不会同时使用命令和参数。在这种情况下,可能只是把整个事情都放在命令中。

您的规范有效,但语法错误。

这样试试

spec:
  containers:
    command: ["/bin/bash"]
    args: ["-c","cat import/initialData.cypher | bin/cypher-shell"]

更新: 在您的 neo4j.conf 中,您必须取消注释与使用 neo4j-shell

相关的行
# Enable a remote shell server which Neo4j Shell clients can log in to.
dbms.shell.enabled=true
# The network interface IP the shell will listen on (use 0.0.0.0 for all interfaces).
dbms.shell.host=127.0.0.1
# The port the shell will listen on, default is 1337.
dbms.shell.port=1337

我发现了我的问题所在。 我没有意识到这些命令没有链接到初始化生命周期,这意味着在容器中启动 neo4j 之前执行了命令。 基本上,使用命令对我来说是错误的方法。