Introducing Warp Factories: open, flexible infrastructure for building your own cloud software factory. [Learn More](/content/factories/index.html)

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:

Bash

```
$ kubectl logs <pod_name>
```

### 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](https://docs.warp.dev/features/warp-ai#starting-warp-ai-from-ai-command-suggestions):

Entering kubernetes get pod logs in the AI Command Suggestions will prompt a 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):

Bash

```
$ kubectl get pods -A
```

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

Bash

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

## 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:

Bash

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

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

Bash

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

## 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:

Bash

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

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:

Bash

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

### 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):

Bash

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

## 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:

Bash

```
$ kubectl logs <resource_type> <resource_name>
```

For example:

Bash

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