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.
error: the path "k8s/deploy.yaml" does not existCommon 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.
pwd && ls -la k8s/
test -f k8s/deploy.yaml || { echo "manifest missing"; exit 1; }
kubectl apply -f k8s/deploy.yamlUse a stable path and ensure the artifact is present
- Reference manifests by a path relative to the repo root (or an absolute path).
- If the manifest is generated, make sure the generating step ran and wrote to the same path.
- Ensure the checkout includes the manifest directory (no over-narrow sparse checkout).
How to prevent it
- Set an explicit
working-directoryfor the apply step. - Assert the manifest exists (
test -f) beforekubectl apply. - Pass generated manifests between steps as artifacts at a known path.