How to get the random pod number provided by Kubernetes

6/13/2019

I would like to get and see the random number provided by K8s.

kubectl logs abc-abc-platform-xxxxx dicom-server

Here xxxxx has to be replaced with the random generated number.

Can you let me know which command do I have to execute to find the random number?

-- The Great
kubectl
kubernetes
kubernetes-helm
minikube

1 Answer

6/13/2019

If the specific pod has the my-app label, you can find that pod and save it as bash variable:

  • POD=$(kubectl get pod -l app=my-app -o jsonpath="{.items[0].metadata.name}")

and then execute:

  • kubectl logs $POD

PS. This will work only if you have 1 pod with that specific label.

-- Ivan Aracki
Source: StackOverflow