Practical Kubernetes Tips for Everyday Ops
A set of practical Kubernetes tips (or how-tos) that may help you in your day-to-day operations. Formating outputs, filtering objects, waiting for pods and more.
Formating outputs
Listing resources
Here is an example kubectl command to list resource of type pod:
$ kubectl -n kube-system get pods
NAME READY STATUS RESTARTS AGE
coredns-7d764666f9-q7mlf 1/1 Running 0 17m
etcd-minikube 1/1 Running 0 17m
kube-apiserver-minikube 1/1 Running 0 17m
kube-controller-manager-minikube 1/1 Running 0 17m
kube-proxy-6p24v 1/1 Running 0 17m
kube-scheduler-minikube 1/1 Running 0 17m
storage-provisioner 1/1 Running 1 (16m ago) 17m
This is the default output. You can use the -o flag to change the output format. For help about using that flag, run kubectl get --help and look for the flag in the Options section or look at formating outputs examples in the Examples section.
Output only resources names
To only output the NAME column run:
$ kubectl -n kube-system get pods -o NAME
pod/coredns-7d764666f9-q7mlf
pod/etcd-minikube
pod/kube-apiserver-minikube
pod/kube-controller-manager-minikube
pod/kube-proxy-6p24v
pod/kube-scheduler-minikube
pod/storage-provisioner
Output additional info
To show additional info like pods IP addresses and nodes names for instance, use:
$ kubectl -n kube-system get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-7d764666f9-q7mlf 1/1 Running 0 28m 10.244.0.2 minikube <none> <none>
etcd-minikube 1/1 Running 0 28m 192.168.49.2 minikube <none> <none>
kube-apiserver-minikube 1/1 Running 0 28m 192.168.49.2 minikube <none> <none>
kube-controller-manager-minikube 1/1 Running 0 28m 192.168.49.2 minikube <none> <none>
kube-proxy-6p24v 1/1 Running 0 28m 192.168.49.2 minikube <none> <none>
kube-scheduler-minikube 1/1 Running 0 28m 192.168.49.2 minikube <none> <none>
storage-provisioner 1/1 Running 1 (27m ago) 28m 192.168.49.2 minikube <none> <none>
Show labels
To show labels in the output, you can use:
$ kubectl -n kube-system get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
coredns-7d764666f9-n2pxg 1/1 Running 0 6m20s k8s-app=kube-dns,pod-template-hash=7d764666f9
etcd-minikube 1/1 Running 0 6m25s component=etcd,tier=control-plane
kube-apiserver-minikube 1/1 Running 0 6m25s component=kube-apiserver,tier=control-plane
kube-controller-manager-minikube 1/1 Running 0 6m25s component=kube-controller-manager,tier=control-plane
kube-proxy-5zlr9 1/1 Running 0 6m20s controller-revision-hash=9b7b96d6c,k8s-app=kube-proxy,pod-template-generation=1
kube-scheduler-minikube 1/1 Running 0 6m27s component=kube-scheduler,tier=control-plane
storage-provisioner 1/1 Running 1 (5m49s ago) 6m23s addonmanager.kubernetes.io/mode=Reconcile,integration-test=storage-provisioner
Customize output columns
You can also customize the column that are shown in the output. Here is an example:
$ kubectl get pods -n kube-system -o custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace
NAME NAMESPACE
coredns-7d764666f9-q7mlf kube-system
etcd-minikube kube-system
kube-apiserver-minikube kube-system
kube-controller-manager-minikube kube-system
kube-proxy-6p24v kube-system
kube-scheduler-minikube kube-system
storage-provisioner kube-system
You could also use a custom columns template file instead of specifying the custom columns in the command. Here is an equivalent template file (template.txt) content for the preceding output:
NAME NAMESPACE
metadata.name metadata.namespace
To use the template file to format the output, run:
$ kubectl -n kube-system get pods -o custom-columns-file=template.txt
NAME NAMESPACE
coredns-7d764666f9-q7mlf kube-system
etcd-minikube kube-system
kube-apiserver-minikube kube-system
kube-controller-manager-minikube kube-system
kube-proxy-6p24v kube-system
kube-scheduler-minikube kube-system
storage-provisioner kube-system
Output JSON and YAML
You can also output info about resources using YAML or JSON formats. Here are example commands:
# Only showing the first 20 lines of the outputs
$ kubectl -n kube-system get pods etcd-minikube -o json | head -n 20
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"annotations": {
"kubeadm.kubernetes.io/etcd.advertise-client-urls": "https://192.168.49.2:2379",
"kubernetes.io/config.hash": "5ff8e3b06bbaa8cb7ebc2bf531e48a2f",
"kubernetes.io/config.mirror": "5ff8e3b06bbaa8cb7ebc2bf531e48a2f",
"kubernetes.io/config.seen": "2026-07-29T05:53:15.399573935Z",
"kubernetes.io/config.source": "file"
},
"creationTimestamp": "2026-07-29T05:53:15Z",
"generation": 1,
"labels": {
"component": "etcd",
"tier": "control-plane"
},
"name": "etcd-minikube",
"namespace": "kube-system",
"ownerReferences": [
$ kubectl -n kube-system get pods etcd-minikube -o yaml | head -n 20
apiVersion: v1
kind: Pod
metadata:
annotations:
kubeadm.kubernetes.io/etcd.advertise-client-urls: https://192.168.49.2:2379
kubernetes.io/config.hash: 5ff8e3b06bbaa8cb7ebc2bf531e48a2f
kubernetes.io/config.mirror: 5ff8e3b06bbaa8cb7ebc2bf531e48a2f
kubernetes.io/config.seen: "2026-07-29T05:53:15.399573935Z"
kubernetes.io/config.source: file
creationTimestamp: "2026-07-29T05:53:15Z"
generation: 1
labels:
component: etcd
tier: control-plane
name: etcd-minikube
namespace: kube-system
ownerReferences:
- apiVersion: v1
controller: true
kind: Node
Output only specific objects fields
To show info only from specific fields of the previous JSON or YAML outputs you can use the following command:
$ kubectl -n kube-system get pods etcd-minikube -o jsonpath={.metadata.creationTimestamp}
2026-07-29T05:53:15Z
Filtering objects
Using labels
You can filter Kubernetes objects through their labels as follows:
$ kubectl get pods -n kube-system -l k8s-app=kube-dns
NAME READY STATUS RESTARTS AGE
coredns-7d764666f9-9hmxc 1/1 Running 0 2m45s
You can specify multiple filtering labels (key=value) by separating them with commas or specifying the -l or --selector flag multiple times. Only resources matching all the specified labels will be shown.
Using objects fields
Overview
You can also filter objects through specific objects fields. Here is for instance a truncated JSON of a pod:
$ kubectl get pods -n kube-system coredns-7d764666f9-9hmxc -o yaml | head -n 10
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2026-08-06T06:33:32Z"
generateName: coredns-7d764666f9-
generation: 1
labels:
k8s-app: kube-dns
pod-template-hash: 7d764666f9
name: coredns-7d764666f9-9hmxc
(...)
You can filter pods resources to only show the pod above by using a specific field inside its JSON as follows:
$ kubectl get pods -n kube-system --field-selector metadata.name=coredns-7d764666f9-9hmxc
NAME READY STATUS RESTARTS AGE
coredns-7d764666f9-9hmxc 1/1 Running 0 8m57s
Only a limited set of objects fields are supported by the --field-selector flag.
Filtering events
Here are examples for filtering events:
# Get eventsonly for a specific Pod
$ kubectl -n kube-system get events --field-selector=involvedObject.name=coredns-7d764666f9-rhktv
LAST SEEN TYPE REASON OBJECT MESSAGE
2m56s Normal Scheduled pod/coredns-7d764666f9-rhktv Successfully assigned kube-system/coredns-7d764666f9-rhktv to minikube
2m55s Normal Pulled pod/coredns-7d764666f9-rhktv Container image "registry.k8s.io/coredns/coredns:v1.13.1" already present on machine and can be accessed by the pod
2m55s Normal Created pod/coredns-7d764666f9-rhktv Container created
2m55s Normal Started pod/coredns-7d764666f9-rhktv Container started
2m31s Warning Unhealthy pod/coredns-7d764666f9-rhktv Readiness probe failed: HTTP probe failed with statuscode: 503
# Get only events of type Warning for that Pod
$ kubectl -n kube-system get events --field-selector=involvedObject.name=coredns-7d764666f9-rhktv,type=Warning
LAST SEEN TYPE REASON OBJECT MESSAGE
7m1s Warning Unhealthy pod/coredns-7d764666f9-rhktv Readiness probe failed: HTTP probe failed with statuscode: 50
To see events object fields to know which ones you can use for selection, use the JSON output. Here is an example truncated output:
$ kubectl -n kube-system get events -o json | head -n 40
{
"apiVersion": "v1",
"items": [
{
"apiVersion": "v1",
"count": 1,
"eventTime": null,
"firstTimestamp": "2026-08-07T22:24:17Z",
"involvedObject": {
"apiVersion": "v1",
"kind": "Pod",
"name": "coredns-7d764666f9-rhktv",
"namespace": "kube-system",
"resourceVersion": "353",
"uid": "dda3f0b7-546d-41fb-9354-c3c80cc9b713"
},
"kind": "Event",
"lastTimestamp": "2026-08-07T22:24:17Z",
"message": "Successfully assigned kube-system/coredns-7d764666f9-rhktv to minikube",
"metadata": {
"creationTimestamp": "2026-08-07T22:24:17Z",
"name": "coredns-7d764666f9-rhktv.18c9a63131d82df5",
"namespace": "kube-system",
"resourceVersion": "357",
"uid": "9e75e6ba-df73-4d0c-8c09-6e2ffb8d9a68"
},
"reason": "Scheduled",
"reportingComponent": "default-scheduler",
"reportingInstance": "",
"source": {
"component": "default-scheduler"
},
"type": "Normal"
},
{
"apiVersion": "v1",
"count": 1,
"eventTime": null,
"firstTimestamp": "2026-08-07T22:24:18Z",
"involvedObject": {
(...)
Filtering pods by status
Use the status.phase objects field for that. Will have the following values:
Running- for running podsFailed- for failed pods
# Only list pods with Running status
kubectl get pods -n mynamspace --field-selector status.phase=Running
# Only list pods in error
kubectl get pods -n mynamspace --field-selector status.phase=Failed
Waiting for pods
Imagine you have scaled down a deployment for instance and want to be sure that all the deployment pods are properly deleted before scaling up.
You can use the following command to wait for pods to be deleted:
# By name
kubectl -n mynamespace wait --for=delete pod/myapp --timeout=60s
# By labels
kubectl -n mynamespace wait --for=delete pod -l app.kubernetes.io/name=myapp --timeout=60s
When waiting for a bunch of pods with same labels, if jobs pods are part of the selection, the wait will not succeed. To filter out jobs pods (succeeded ones for isntance), use the --field-selector flag as follows:
kubectl -n mynamespace wait --for=delete pod -l app.kubernetes.io/name=myapp --field-selector status.phase!=Succeeded --timeout=60s
You can also wait for a specific pod condition (Ready for instance) as follows:
kubectl -n mynamespace wait --for=condition=Ready=True pod -l app.kubernetes.io/name=myapp --field-selector status.phase!=Succeeded --timeout=60s
Other stuff
Adding a single file into containers FS using volumes
(...)
volumes:
- name: app-config
configMap:
name: app-config
items: # we want the file inside the container to be called .env
- key: config.env
path: .env
containers:
- name: app
volumeMounts:
- name: app-config
mountPath: /app/config/.env
subPath: .env # this creates the /app/config/.env and keep the old files
Here is the result:
#----------------------#
# With 'subPath: .env' #
#----------------------#
/app $ ls -lah config/
total 24K
drwxr-xr-x 1 www-data www-data 4.0K Oct 10 14:59 .
drwxr-xr-x 1 www-data www-data 4.0K Oct 9 15:07 ..
-rw-r--r-- 1 root www-data 377 Oct 10 14:59 .env # <= a file
-rwxr-xr-x 1 www-data www-data 3.0K Oct 9 15:07 config.inc.php
-rwxr-xr-x 1 www-data www-data 629 Oct 9 15:07 config_env.php
# Accessing the mounted file
/app $ cat config/.env
MYVAR=VALUE
#-------------------------#
# Without 'subPath: .env' #
#-------------------------#
/app $ ls -lah config/
total 24K
drwxr-xr-x 1 www-data www-data 4.0K Oct 10 15:13 .
drwxr-xr-x 1 www-data www-data 4.0K Oct 9 15:07 ..
drwxrwsrwx 3 root www-data 4.0K Oct 10 15:13 .env # <= a directory
-rwxr-xr-x 1 www-data www-data 3.0K Oct 9 15:07 config.inc.php
-rwxr-xr-x 1 www-data www-data 629 Oct 9 15:07 config_env.php
# Accessing the mounted file
/app $ cat config/.env/.env
MYVAR=VALUE
Want to report a mistake or ask questions ? Feel free to email me at gmkziz@hackerstack.org. I will be glad to answer.
If you like my articles, consider registering to my newsletter in order to receive the latest posts as soon as they are available.
Take care, keep learning and see you in the next post 🚀