我正在使用NodeJS构建基于Istio/K8s的平台,用于控制流量路由。我需要能够以编程方式修改自定义资源,并希望使用@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)
virtual-service.yaml:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: message-service
spec:
hosts:
- message-service
http:
- name: 'production'
route:
- destination:
host: message-service
weight: 100
retries:
attempts: 3
perTryTimeout: 2s
retryOn: 5xx
message: '请求的主体格式未知 - 可接受的媒体类型包括:application/json-patch+json、application/merge-patch+json、application/apply-patch+yaml',reason: 'UnsupportedMediaType',code: 415
。 - undefinedreplaceNamespacedCustomObject
作为替代方案吗?只是为了看看它是否有效。 - undefinedvirtualservices.networking.istio.io "message-service" 无效:metadata.resourceVersion: 无效的值:0x0:必须为更新指定
。上面附上了我的VirtualService规范。 - undefined