# Troubleshoot

Find what you see, run the first check, then follow the link.

## Start with the objects and their events

Start with what the cluster says needs attention. It lists failed node
updates, machines that did not launch, node pool credentials that fail and
Ingresses with no class, each with its fix:

```bash
kite status
```

Then read the object and its events before you retry anything:

```bash
kubectl describe pod <pod> -n <namespace>
kubectl get events -n <namespace> --watch
```

On a node:

```bash
sudo kite-agent status
sudo kite-agent logs
```

## Find the check for a symptom

| What you see                                                           | First check                                                              | Fix                                                                                                                                                             |
| ---------------------------------------------------------------------- | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The local cluster does not start                                       | `kite local status`, then `kite local logs control`                      | [If something goes wrong](/docs/quickstart/#if-something-goes-wrong)                                                                                            |
| `kite deploy` says `a Worker called <name> is already in this account` | Whether this settings file deployed that Worker                          | [How `kite deploy` changes the Worker](/docs/configure/#how-kite-deploy-changes-the-worker)                                                                     |
| `kite deploy` says `this account has no workers.dev subdomain`         | The account's Workers settings in the Cloudflare dashboard               | [If something goes wrong](/docs/deploy-cloudflare/#if-something-goes-wrong)                                                                                     |
| `kubectl` cannot authenticate after a deploy                           | `KITE_ADMIN_TOKEN` in the settings file                                  | [Recover from common failures](/docs/configure/#recover-from-common-failures)                                                                                   |
| `kite login` is refused, or `kubectl` returns `Forbidden`              | `kite whoami`, and the RBAC binding for the subject it prints            | [Troubleshoot sign-in](/docs/sign-in/#troubleshoot-sign-in)                                                                                                     |
| A host cannot join, or a node is `NotReady`                            | The error `kite node add` prints, then `sudo kite-agent logs`            | [Check a joined host](/docs/manage-nodes/#check-a-joined-host)                                                                                                  |
| A pod stays `Pending`                                                  | `FailedScheduling` events                                                | [Events](/docs/reference/events/#event-reasons)                                                                                                                 |
| A deleted pod stays `Terminating`                                      | `FailedKillPod` events, then `sudo kite-agent logs` on the pod's node    | [Events](/docs/reference/events/#event-reasons)                                                                                                                 |
| A node pool creates no machine                                         | `kubectl describe nodepool` and `kubectl describe nodeclaim`             | [If no node appears](/docs/set-up-node-pools/#if-no-node-appears)                                                                                               |
| A pod stays `Pending` with a `NoNodePoolFits` event                    | The event's message, which gives each pool's reason for refusing the pod | Change the pod's requests, selector or tolerations, or add a pool that offers what it asks for ([Node pool reasons](/docs/reference/events/#node-pool-reasons)) |
| `ErrImagePull` or `ImagePullBackOff`                                   | The image name, `imagePullSecrets`, and the host's registry access       | [Image pull failures](#image-pull-failures)                                                                                                                     |
| A container waits with `PostStartHookError`                            | The waiting state's message in `kubectl describe pod`                    | [Hook failures](#hook-failures)                                                                                                                                 |
| A container waits with `CrashLoopBackOff`                              | `kubectl logs --previous`, then the last state in `kubectl describe pod` | [Restart back-off](#restart-back-off)                                                                                                                           |
| A volume does not mount                                                | `FailedMount` events, then `kubectl get csinode`                         | [Volume access](#volume-access)                                                                                                                                 |
| A Service or another pod is unreachable                                | `kubectl get endpointslice`, then the Node's `NodeNetworkStatus`         | [Network failures](#network-failures)                                                                                                                           |
| An Ingress gets no hostname                                            | `kubectl describe ingressclass <class>`                                  | [Expose a workload](/docs/expose/)                                                                                                                              |
| The public hostname returns `404`                                      | `kubectl describe ingress <name>` for a matching host and path           | [Expose a workload](/docs/expose/)                                                                                                                              |
| The public hostname responds, but not from the workload                | The Service's EndpointSlices, then the `<class>-tunnel` Deployment       | [Create an HTTP workload and route](/docs/expose/#3-create-an-http-workload-and-route)                                                                          |

## Image pull failures

A pod pulls its images with the credentials in the Secrets that its
`imagePullSecrets` lists. To read the list, run:

```bash
kubectl get pod <pod> -n <namespace> -o jsonpath='{.spec.imagePullSecrets}'
```

- A pod that is created with no `imagePullSecrets`, or an empty list, gets its
  ServiceAccount's.
- A pod that names any keeps only its own, so a pod that names one Secret must
  name every Secret that its images need.

A pod keeps the list that it was created with, so a change to the
ServiceAccount's list reaches only the pods created after it.

Each Secret must be in the pod's namespace and have a `.dockerconfigjson` or
`.dockercfg` key with an entry for the image's registry. If the Secrets are
right, check that the host can reach the registry, as
[What you need](/docs/manage-nodes/#what-you-need) describes.

## Network failures

1. Run `kubectl get nodes` and confirm the node is Ready.
2. Run `kubectl get nodenetworkstatus <node> -o yaml`, and read its `unreachablePeers` and `unreachableFrom` fields. Each node has a `NodeNetworkStatus` with the node's name.
3. Run `kubectl describe pod <pod> -n <namespace>`. Confirm the pod has an address and read its events.
4. Check that UDP traffic gets through to every peer endpoint. Confirm that neither the pod range nor the Service range overlaps your network.
5. Run `sudo kite-agent logs` on the host. Look for CNI, WireGuard, route, nftables, DNS or API-address errors.

## Hook failures

When a container's postStart hook fails, as in Kubernetes:

1. The node stops the container. Its `Killing` Event has the message
   `FailedPostStartHook`. Its preStop hook runs within the Pod's
   `terminationGracePeriodSeconds`, and the container gets the rest of that
   time, at least 2 seconds.
2. The container waits for its next run with the reason `PostStartHookError`.
3. While its restart waits, the container shows `CrashLoopBackOff` in place of
   `PostStartHookError`. See [Restart back-off](#restart-back-off).

| Hook      | Where to read its error                                                                                           |
| --------- | ----------------------------------------------------------------------------------------------------------------- |
| postStart | The waiting state's message in `kubectl describe pod`: the hook's error, with the end of what its command printed |
| preStop   | `sudo kite-agent logs` on the Pod's node                                                                          |

:::note
As in Kubernetes, a `FailedPostStartHook` or `FailedPreStopHook` Event's
message is `PostStartHook failed` or `PreStopHook failed`, without the hook's
error.
:::

### httpGet hooks and probes

These follow Kubernetes:

- An httpGet hook passes whatever status its server answers with, such as 500,
  and fails when its request gets no response.
- An httpGet hook and an httpGet probe follow a 301, 302, 303, 307 or 308 on
  the host that they first request, at any port or scheme. The tenth redirect
  fails them.
- Any other redirect, such as one to another host, is the response: a hook
  passes, and a probe passes with a `ProbeWarning` Event that quotes the
  response's body.
- A `Host` header from `httpHeaders` is sent again only after a relative
  `Location`.
- When the server of an HTTPS httpGet hook answers in plain HTTP, the node
  sends the hook again over HTTP, without its `Authorization` header. If that
  request gets a response, the hook passes, and the Pod has one
  `LifecycleHTTPFallback` Warning Event that names the hook's host and port.

## Restart back-off

When a container exits and the node runs it again, each restart after the
first waits, as in Kubernetes:

- The wait starts at 10 seconds and doubles up to 5 minutes.
- A run that lasts more than 10 minutes restarts at once, and the next wait
  starts again at 10 seconds.

While the container waits, `kubectl get pods` shows `CrashLoopBackOff`: the
container's state is waiting with that reason, its last state is the run that
exited, and it has a `BackOff` Event. The waiting state's message gives the
wait:

```text
back-off 40s restarting failed container=app pod=web-0_default(<uid>)
```

To find what makes the container exit, run `kubectl logs --previous`, then
read the last state in `kubectl describe pod`.

## Volume access

Run `kubectl get csinode` to see the CSI drivers that each node has reported.
Install or fix any driver that a node does not list.

If a pod cannot mount a volume, read `kubectl describe pod <pod> -n <namespace>`,
the CSI driver's logs, and `sudo kite-agent logs` on the host.

## Next

- [Events](/docs/reference/events/): event reasons and how long Events stay.
- [How it works](/docs/how-it-works/): where each part runs.
