连接到Google Container Engine上创建的Kubernetes apiserver(node.js)

时间:2015-10-26 15:54:08

标签: google-cloud-platform kubernetes google-kubernetes-engine

我已通过googleapis nodejs client成功连接到容器引擎并获取群集对象(根据文档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)

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

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