Skip to content
Latchkey

kubectl "error: the path ... does not exist" - Fix -f Paths in CI

kubectl could not find the file or directory passed to -f. This is a filesystem problem on the runner - a wrong working directory, a path relative to the wrong place, or a manifest that was never generated or checked out.

What this error means

kubectl apply -f <path> fails immediately with error: the path "<path>" does not exist. Nothing is sent to the cluster - kubectl never found the manifest to read.

kubectl output
error: the path "k8s/deploy.yaml" does not exist

Common causes

Wrong working directory

The path is relative and the step runs from a different directory than expected, so the relative path does not resolve. CI working directories differ from local shells.

Manifest not generated or not checked out

A templated/kustomized manifest produced by an earlier step is missing (the step failed or wrote elsewhere), or a sparse/shallow checkout omitted the directory.

How to fix it

Confirm the file exists from the step’s CWD

List the path before applying so CI fails with a clear message if it is missing.

Terminal
pwd && ls -la k8s/
test -f k8s/deploy.yaml || { echo "manifest missing"; exit 1; }
kubectl apply -f k8s/deploy.yaml

Use a stable path and ensure the artifact is present

  1. Reference manifests by a path relative to the repo root (or an absolute path).
  2. If the manifest is generated, make sure the generating step ran and wrote to the same path.
  3. Ensure the checkout includes the manifest directory (no over-narrow sparse checkout).

How to prevent it

  • Set an explicit working-directory for the apply step.
  • Assert the manifest exists (test -f) before kubectl apply.
  • Pass generated manifests between steps as artifacts at a known path.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →