Answer of rcorre is correct but for N resources it make N requests to cluster (so for a lot of resources this approach is very slow). Moreover, not found resources (that have not instances) are very slow for getting with kubectl get
.
There is a better way to make a request for multiple resources:
kubectl get pods,svc,secrets
instead of
kubectl get pods
kubectl get svc
kubectl get secrets
So the answer is:
#!/usr/bin/env bash
# get all names and concatenate them with comma
NAMES="$(kubectl api-resources \
--namespaced \
--verbs list \
-o name \
| tr '\n' ,)"
# ${NAMES:0:-1} -- because of `tr` command added trailing comma
# --show-kind is optional
kubectl get "${NAMES:0:-1}" --show-kind
or
#!/usr/bin/env bash
# get all names
NAMES=( $(kubectl api-resources \
--namespaced \
--verbs list \
-o name) )
# Now join names into single string delimited with comma
# Note *, not @
IFS=,
NAMES="${NAMES[*]}"
unset IFS
# --show-kind is enabled implicitly
kubectl get "$NAMES"