How to get the custom attributes in Kubernetes?

3/27/2020

How to list the current deployments running in Kubernetes with custom columns displayed as mentioned below:

DEPLOYMENT CONTAINER_IMAGE READY_REPLICAS NAMESPACE

The data should be sorted by the increasing order of the deployment name.

-- Yash Bindlish
kubernetes
kubernetes-deployment

2 Answers

3/27/2020

Command to get the custom columns as per the question:

Kubectl get deployments -o custom-columns=DEPLOYMENT:.metadata.name,CONTAINER_IMAGE:..image,READY_REPLICAS:..replicas,NAMESPACE:..namespace

-- Yash Bindlish
Source: StackOverflow

3/27/2020

Look a the -o custom-columns feature. https://kubernetes.io/docs/reference/kubectl/overview/#custom-columns shows the basics. The hard one would be container_image, since a pod can contain more than one, but assuming you just want the first, something like .spec.template.containers[0].image? Give a shot and see how it goes.

-- coderanger
Source: StackOverflow