Skip to content
Latchkey

kubectl apply: Deploy Manifests in CI

Create or update Kubernetes resources from manifests declaratively.

kubectl apply reconciles cluster state toward the manifests you provide, creating resources that are missing and patching ones that drifted. It is the backbone of GitOps-style and CI-driven deploys. Use --dry-run=server to validate before applying for real.

Common flags

  • -f file.yaml - apply a manifest or directory
  • -k dir - apply a kustomize overlay
  • -n NAMESPACE - target namespace
  • --dry-run=server - validate against the API server without persisting
  • --prune - delete resources no longer in the manifest set

Example in CI

Apply a directory of manifests to production.

shell
kubectl apply -f k8s/ --namespace prod

Common errors in CI

  • the server could not find the requested resource - wrong apiVersion or CRD not installed
  • Unable to connect to the server - kubeconfig not set or wrong context
  • error validating data: ValidationError - schema mismatch in the manifest

Key takeaways

  • Declaratively reconciles cluster state to your manifests.
  • Validate with --dry-run=server before applying in CI.
  • Most failures are a wrong apiVersion or an unset kubeconfig.

Related guides

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