Kubernetes Error: validation failed – no matches for kind ‘Deployment’

Updated: January 31, 2024 By: Guest Contributor Post a comment

Understanding the Error

Encountering ‘no matches for kind “Deployment”‘ indicates that Kubernetes does not recognize the ‘Deployment’ resource in the provided context. Centered around invalid API versions, missing custom resource definitions (CRDs), or incorrect Kubernetes context, it often leads to a halt in deployment processes.

Solutions

Different solutions are tied with varying contexts of this error. Approaching this error begins with identifying the root cause, which can either be an incorrect API version in the manifest files or missing resources in the Kubernetes cluster.

Solution 1: Update API Version

Kubernetes manifests reference specific API versions that evolve. Updating the API version can correct mismatches.

  1. Verify the current Kubernetes version.
  2. Review the Kubernetes documentation to align with the correct API version.
  3. Edit the manifest file to update the apiVersion field.
  4. Redeploy using kubectl apply.

Example:

kubectl version
# Edit the deployment.yaml file
# Change the apiVersion from apps/v1beta1 to apps/v1

kubectl apply -f deployment.yaml

Notes: Ensure compatibility with the updated API version. Some features might differ, requiring manifest adjustments.

Solution 2: Install Missing CRDs

Custom resources require definitions. Install missing CRDs if utilizing custom deployment kinds.

  1. Identify the missing CRDs.
  2. Retrieve the CRD manifests from the respective sources.
  3. Install CRDs using kubectl apply.

Example:

kubectl apply -f custom-crd.yaml

Notes: Custom resources have corresponding documentation. Consult for details regarding the setup.

Solution 3: Correct Namespace or Context

Kubernetes’ context or namespace issues can trigger this error. Set the correct context or namespace before deployment.

  1. Check the current context and namespace.
  2. Switch to the appropriate ones with kubectl config.
  3. Apply the deployment manifest once aligned.

Example:

kubectl config get-contexts
kubectl config use-context desired-context
kubectl apply -f deployment.yaml

Notes: Some deployments might target a specific namespace. Verify before executing commands.

Persisting issues might necessitate a thorough inspection. Utilize verbose logging with kubectl via the --v=6 or --v=8 flags to gain insights.