The usual way to describe a resource with kubectl is to call it by its name and namespace. For example,
$ kubectl get pod gke-metadata-server-qqmt6 -n kube-system
NAME READY STATUS RESTARTS AGE
gke-metadata-server-qqmt6 1/1 Running 0 31h
To get two resources, one can simply type both names at once. However for large number of resources, it is more convenient to provide a file containing a list of resources. This is the role of the option -f
for describe
or get
. Unfortunately, the documentation is rather limited:
List a pod identified by type and name specified in “pod.yaml” in JSON output format.
kubectl get -f pod.yaml -o json
I would have appreciated a bit more details: how does this file should look like? And how can we add several resources to the same file? There is nothing complicated, but since I couldn’t find any example on the Internet (it’s probably too obvious!), here is mine:
$ cat pods.yaml
apiVersion: v1
items:
- apiVersion: v1
kind: Pod
metadata:
name: gke-metadata-server-qqmt6
namespace: kube-system
- apiVersion: v1
kind: Pod
metadata:
name: kube-dns-autoscaler-645f7d66cf-t49wb
namespace: kube-system
kind: List
$ kubectl get -f pods.yaml
NAME READY STATUS RESTARTS AGE
gke-metadata-server-qqmt6 1/1 Running 0 31h
kube-dns-autoscaler-645f7d66cf-t49wb 1/1 Running 0 3d17h
I gave a simple example, but the same technique is useful to automate workflows that manipulate other resources, for example with the Argo Kubernetes resource template.