【问题标题】:ChildProcessError: stdout maxBuffer length exceededChildProcessError:超出标准输出最大缓冲区长度
【发布时间】:2021-09-02 16:04:46
【问题描述】:

我们有以下代码(不要问我为什么......即使作为非 JavaScript 开发人员,它对我来说看起来也不漂亮),在 Kubernetes 升级后会引发错误:

module.exports.getReplicationControllers = async function getReplicationControllers(namespace) {
  const kubeConfig = (await getNamespacesByCluster()).get(namespace);
  if (!kubeConfig) throw new Error(`No clusters contain the namespace ${namespace}`)
  const kubeConfigEscaped = shellEscape([kubeConfig]);

  const namespaceEscaped = shellEscape([namespace]);
  const result = await cpp(`kubectl --kubeconfig ${kubeConfigEscaped} get replicationcontrollers -o json -n ${namespaceEscaped}`);
  console.error(result.stderr);
  /** @type {{items: any[]}} */
  const resultParsed = JSON.parse(result.stdout);
  const serviceNames = resultParsed.items.map((item) => item.metadata.name);
  return serviceNames;
}

ChildProcessError: stdout maxBuffer length exceeded kubectl --kubeconfig /kubeconfig-staging get replicationcontrollers -o json -n xxx(以错误代码 ERR_CHILD_PROCESS_STDIO_MAXBUFFER 退出)

到目前为止我尝试过的是:

  const result = await cpp(`kubectl --kubeconfig ${kubeConfigEscaped} get replicationcontrollers -o=jsonpath='{.items[*].metadata.name}' -n ${namespaceEscaped}`);
  console.error(result.stderr);
  const serviceNames = result.split(' ');
  return serviceNames;

返回

TypeError: result.split 不是函数

我不是非常精通 JavaScript,感谢任何帮助。

【问题讨论】:

  • 有一个official Javascript Kubernetes client;你能用它来代替kubectl吗? (这可能会更简单、更安全;GitHub 页面上的第一个示例列出了 pod,并且很容易将其调整为列出复制控制器或其他对象类型。)

标签: javascript node.js kubernetes


【解决方案1】:

一般性地回答问题(而不是让您切换到其他工具),对于有此问题并且可能正在使用其他应用程序的人:

RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]:超出标准输出最大缓冲区长度

问题是由于您的命令向 stdout 或 stderr 发送了大量数据(超过 1MB)所致。

在 exec() 中为 the node docs for process.exec 增加 maxBuffer 选项

exec(someCommand, {
  maxBuffer: 5 * 1024 * 1024,
})

【讨论】:

    猜你喜欢
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    相关资源
    最近更新 更多