How to get Kubernetes HTTP Request response in yaml instead of json

4/6/2020

I i'm making Kubernetes HTTP Request GET /apis/apps/v1/namespaces/{namespace}/deployments/{name}

This gives response in json but i want response in json.

Does Kubernetes give response in yaml? if yes, let me know how to do it?

-- Venky Ohana
httprequest
kubernetes

1 Answer

4/6/2020

When running curl requests you can tell api-server to send you yaml formated output by setting Accept: application/yaml header. Take a look at example below:

curl --header "Accept: application/yaml" "/apis/[...]"

Or you can also use some external tool to convert from json to yaml, e.g. yq:

curl "/apis/[...]" | yq -y .

where -y stands for yaml output.

-- HelloWorld
Source: StackOverflow