• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Get Kubernetes Logs With kubectl

Thumbnail for Ekene EjikeThumbnail for Ekene EjikeThumbnail for Ekene EjikeThumbnail for Ekene Ejike
Ekene Ejike

Ekene Ejike

Updated: 8/13/2024

Published: 2/9/2024

About Terminus

In Kubernetes, the easiest way to troubleshoot a pod, deployment, or service in a cluster stuck in an error state such as CrashloopBackoff, ImagePullBackoff, or Pending, is to access and review its logs.

The short answer

In Kubernetes, to get the logs of a specific pod, you can use the kubectl logs command as follows:

$ kubectl logs <pod_name>

Run in Warp

Easily retrieve this command using Warp’s AI Command Suggestions

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Entering kubernetes get pod logs in the AI Command Suggestions will prompt an kubectl command that can then quickly be inserted into your shell by doing CMD+ENTER.

Getting the logs of a pod in a namespace

To get the logs of a pod in a namespace, you can start by first listing all the pods using the kubectl get pods command with the -A flag (short for --all-namespaces):

$ kubectl get pods -A

Run in Warp

Then use the kubectl logs command with the -n flag (short for --namespace) as follows:

$ kubectl logs <pod_name> -n <namespace>

Run in Warp

Getting the logs of a pod in real-time

To quickly troubleshoot a pod issue, you can continuously stream the logs of that pod into the terminal in real-time using the kubectl logs command with the -f flag (short for --follow) as follows:

$ kubectl logs <pod> -n <namespace> -f

Run in Warp

Note that this flag can also be combined with the -c flag to stream the logs of a specific container within the pod:

$ kubectl logs <pod> -n <namespace> -c <container> -f

Run in Warp

Getting the logs of a container within a pod

In some cases, pods may contain more than one container. To get the logs of a specific container within a pod, you can use the kubectl logs command with the -c flag (short for --container) as follows:

$ kubectl logs <pod_name> -n <namespace> -c <container_name>

Run in Warp

Note that the -c flag is not necessary when there is only one container running within a pod.

Getting the logs from all the containers within a pod

Alternatively, to get the logs from all the containers running within a pod at once, you can use the --all-containers flag as follows:

$ kubectl logs<pod_name> -n <namespace> --all-containers=true

Run in Warp

Getting the logs of a crashed container

By default, the kubectl logs command only retrieves the logs of a running container within a pod. When a container crashes, you can still troubleshoot or get the logs from a previous running instance of that pod using the kubectl logs command with the -p flag (short for --previous):

$ kubectl logs <pod_name> -n <namespace> -p 

Run in Warp

Getting the logs of a specified resource

To get the logs of a specified resource, such as a Deployment, a Service, a Job, etc, you can use the kubectl logs command as follows:

$ kubectl logs <resource_type> <resource_name>

Run in Warp

For example:

$ kubectl logs deployment <deployment_name>
$ kubectl logs job <job_name>
$ kubectl logs services <service_name>

Run in Warp

Written by

Thumbnail for Ekene EjikeThumbnail for Ekene EjikeThumbnail for Ekene EjikeThumbnail for Ekene Ejike
Ekene Ejike

Ekene Ejike

Filed Under

Related Articles

Copy Files From Pod in Kubernetes

Learn how to copy files and directories from within a Kubernetes Pod into the local filesystem using the kubectl command.

Kubernetes
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Scale Deployments in Kubernetes

Learn how to manually and automatically scale a Deployment based on CPU usage in Kubernetes using the kubectl-scale and kubectl-autoscale commands.

Kubernetes
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Forward Ports In Kubernetes

Learn how to forward the ports of Kubernetes resources such as Pods and Services using the kubectl port-forward command.

Kubernetes

Tail Logs In Kubernetes

Learn how to tail and monitor Kubernetes logs efficiently to debug, trace, and troubleshoot errors more easily using the kubectl command.

Kubernetes

Get Context In Kubernetes

Learn how to get information about one or more contexts in Kubernetes using the kubectl command.

Kubernetes

Delete Kubernetes Namespaces With kubectl

Learn how to delete one or more namespaces and their related resources in a Kubernetes cluster using the kubectl command.

Kubernetes

Get Kubernetes Secrets With kubectl

Learn how to list, describe, customize, sort and filter secrets in a Kubernetes cluster by name, type, namespace, label and more using the kubectl command.

Kubernetes
Thumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi Manhas
Mansi Manhas

List Kubernetes Namespaces With kubectl

Learn how to list, describe, customize, sort and filter namespaces in a Kubernetes cluster by name, label, and more using the kubectl command.

Kubernetes
Thumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi Manhas
Mansi Manhas

How To List Events With kubectl

Learn how to list and filter events in Kubernetes cluster by namespace, pod name and more using the kubectl command.

Kubernetes
Thumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi Manhas
Mansi Manhas

Kubernetes vs Docker: The Backbone of Modern Backend Technologies

Lean the fundamentals of the Kubernetes and Docker technologies and how they interplay with each other.

KubernetesDocker
Thumbnail for Gabriel ManricksThumbnail for Gabriel ManricksThumbnail for Gabriel ManricksThumbnail for Gabriel Manricks
Gabriel Manricks

Set Context With kubectl

Learn how to create, modify, switch, and delete a context in Kubernetes using the kubectl config command.

Kubernetes
Thumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi Manhas
Mansi Manhas

List Pods With kubectl

Learn how to list and filter Kubernetes Pods by name, namespaces, labels, manifests, and more using the kubectl command.

Kubernetes
Thumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi ManhasThumbnail for Mansi Manhas
Mansi Manhas

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for nullThumbnail for nullThumbnail for nullThumbnail for null