k8s commands to display container logs

Petr Kostelanský | 26 May 2024
How to get logs from app running in Kubernetes by kubectl logs command.

Selected namespace for the current context:

kubectl config get-contexts

The context relates to your login to the cluster.

 

You can switch to a different namespace:

kubectl config set-context --current --namespace test-app-dev

 

List all pods in namespace:

kubectl get pods

 

List containers running in a pod:

kubectl get pods test-app-dev-import-cronjob-28594500-54jj2 -o jsonpath='{.spec.containers[*].name}'

 

Show logs from the docker container (test-app-import-cron) running in the pod:

kubectl logs -c test-app-dev-import-cron test-app-dev-import-cronjob-28594500-54jj2
Loading ads...