我正在构建基于 Istio/K8s 的平台,用于使用 NodeJS 控制流量路由。我需要能够以编程方式修改自定义资源,并且我想使用@kubernetes/node-client。我无法在文档和存储库中找到用于访问客户资源的正确 API。我错过了什么吗?谢谢。
编辑:当使用 CustomObjectApi.patchNamespacedCustomObject 函数时,我从 K8s API 返回以下错误:
message: 'the body of the request was in an unknown format - accepted media types include: application/json-patch+json, application/merge-patch+json, application/apply-patch+yaml', reason: 'UnsupportedMediaType', code: 415
我的代码:
const k8sYamls = `${path.resolve(path.dirname(__filename), '..')}/k8sYamls`
const vServiceSpec = read(`${k8sYamls}/${service}/virtual-service.yaml`)
const kc = new k8s.KubeConfig()
kc.loadFromDefault()
const client = kc.makeApiClient(k8s.CustomObjectsApi)
const result = await client.patchNamespacedCustomObject(vServiceSpec.apiVersion.split('/')[0], vServiceSpec.apiVersion.split('/')[1], namespace, 'virtualservices', vServiceSpec.metadata.name, vServiceSpec)
Run Code Online (Sandbox Code Playgroud)
虚拟服务.yaml:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: message-service
spec:
hosts:
- message-service
http: …Run Code Online (Sandbox Code Playgroud)