kubectl get deployments \
-o jsonpath='{.items[?(@.status.replicas != 0)].metadata.name}'
kubectl get deployments \
-o jsonpath='{.items[*].spec.template.metadata.labels}' \
| jq .
If you want the value of a specific label (let's say, app
) this can be more efficient:
kubectl get deployments \
-o jsonpath='{.items[*].spec.template.metadata.labels.app}'
kubectl get services \
-o jsonpath='{.items[*].spec.selector}' \
| jq .
If you want the value of a specific label (let's say, app
) this can be more efficient
kubectl get services \
-o jsonpath='{.items[*].spec.selector.app}'