Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: Display Pods by age in ascending order

I use below command to sort the pods by age

kubectl get pods --sort-by={metadata.creationTimestamp}

It shows up pods in descending order. How can we select sorting order like ascending?

like image 341
P Ekambaram Avatar asked Jul 31 '19 15:07

P Ekambaram


People also ask

How do you scale up and down pods in Kubernetes?

You can autoscale Deployments based on CPU utilization of Pods using kubectl autoscale or from the GKE Workloads menu in the Google Cloud console. kubectl autoscale creates a HorizontalPodAutoscaler (or HPA) object that targets a specified resource (called the scale target) and scales it as needed.

How do you scale pods in Kubernetes command?

The kubectl scale command is used to change the number of running replicas inside Kubernetes deployment, replica set, replication controller, and stateful set objects. When you increase the replica count, Kubernetes will start new pods to scale up your service.


1 Answers

Not supported by kubectl or the kube-apiserver as of this writing (AFAIK), but a workaround would be:

$ kubectl get pods --sort-by=.metadata.creationTimestamp | tail -n +2 | tac

or if tac is not available (MacOS X):

$ kubectl get pods --sort-by=.metadata.creationTimestamp | tail -n +2 | tail -r

If you want the header:

$ echo 'NAME                                                              READY   STATUS             RESTARTS   AGE' | \
 kubectl get pods --sort-by=.metadata.creationTimestamp | tail -n +2 | tac

You might just have to adjust the tabs on the header accordingly. Or if you don't want to use tail -n +2 you can use --no-headers. For example:

$ kubectl get pods --sort-by=.metadata.creationTimestamp --no-headers | tac
like image 119
Rico Avatar answered Oct 16 '22 10:10

Rico