答案 0 :(得分:2)
所有客户端库都是从相同的底层 IDL 自动生成的,因此它的工作方式类似于 Go,createNamespacedCustomObject
。您也可以直接使用原始 API。
答案 1 :(得分:1)
const k8s = require('@kubernetes/client-node')
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sClient = kc.makeApiClient(k8s.CustomObjectsApi);
var body = {
"apiVersion": "something.com/v1alpha1",
"kind": "MyKind",
"metadata": {
"name": "mycustomobject",
},
"spec": {
"size": "1",
"image": "myimage"
}
}
k8sClient.createNamespacedCustomObject('something.com','v1alpha1','default','mykinds', body)
.then((res)=>{
console.log(res)
})
.catch((err)=>{
console.log(err)
})