"If you do nothing, nothing will happen."

프로그래밍

[K8S] API 요청 시 UnsupportedMediaType 에러 발생

tedhong 2023. 4. 3. 16:36

이슈

node.js 에서 K8S client 를 이용해 secret 을 Patch 하려고

patchNamespacedSecret 함수를 쓰는데 계속해서 

"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure",
"message":"415: Unsupported Media Type","reason":"UnsupportedMediaType",
"details":{},"code":415

이런 오류가 발생했다.


해결

 

patchNamespacedSecret  함수의 options 파라메터로 

{ headers: { 'content-type': 'application/merge-patch+json' } }

를 넘겨주니 해결!

 


적용예

await k8sApi.patchNamespacedSecret(serectName, namespace, patchData, 
undefined, undefined, undefined, undefined, undefined,
{ headers: { 'content-type': 'application/merge-patch+json' } }).then((result)=>{
                console.log(result);                
});