jsonkubernetesmetadatakubectljsonpath

How do i add custom column name in output of kubectl jsonpath query


I am using kubectl jsonpath query to display below output:

kubectl get pvc -o=jsonpath='{range .items[*]}{@.metadata.name}{" "}{@.spec.resources.requests.storage}{" "}{@.spec.storageClassName}{"\n"}{end}'

storage-1 100Mi longhorn
storage-2 100Mi longhorn
storage-3 100Mi longhorn
storage-4 100Mi longhorn

I want to add the name of the column i.e

    pvc      capacity  storageclass
  
    storage-1 100Mi longhorn
    storage-2 100Mi longhorn
    storage-3 100Mi longhorn
    storage-4 100Mi longhorn

How do i achieve using the kubectl jspnpath query?


Solution

  • Using JSONPath expressions you may insert {"pvc\\tcapacity\\tstorageclass\\n"} as

    kubectl get pvc -o=jsonpath='{"pvc\tcapacity\tstorageclass\n"}{range .items[*]}{@.metadata.name}{"\t"}{@.spec.resources.requests.storage}{"\t"}{@.spec.storageClassName}{"\n"}{end}'