连接到在 Google 容器引擎 (node.js) 上创建的 Kubernetes apiserver

Connect to Kubernetes apiserver created on Google Container Engine (node.js)

我已通过 googleapis nodejs client and get the cluster object back (according to the doc here) 成功连接到容器引擎,并将 masterAuth 对象保存到磁盘上的 json 文件中。但是,我仍然不知道如何向 apiserver 发出经过身份验证的请求:

var request = require("request");
var key = require("path/to/key/json");
var options = {
    url: "https://IPofKubernetesCluster/api/v1/endpoints",
    cert: key.clientCertificate,
    ca: key.clusterCaCertificate,
    key: key.clientKey,
    passphrase: null
};
request.get(options, function(e, r, body) {});

代码失败,出现以下错误:

crypto.js:131
      c.context.setKey(options.key);
            ^
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
    at Object.exports.createCredentials (crypto.js:131:17)
    at Object.exports.connect (tls.js:1345:27)
    at Agent.createConnection (https.js:79:14)
    at Agent.createSocket (http.js:1294:16)
    at Agent.addRequest (http.js:1270:23)
    at new ClientRequest (http.js:1417:16)
    at Object.exports.request (https.js:123:10)
    at Request.start(node_modules/request/request.js:793:30)
    at Request.end (node_modules/request/request.js:1400:10)
    at end (node_modules/request/request.js:564:14)

如有任何帮助,我们将不胜感激。

MasterAuth structure 包括 base64 编码的 客户端和集群证书。在将字符串传递到您的 http 客户端库之前,您需要将它们解码回 PEM 格式。