Sling Academy
Home/DevOps/Kubernetes Error: validation failed – no matches for kind ‘Deployment’

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

Last updated: January 31, 2024

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.

Next Article: How to Completely Remove a Kubernetes Deployment (with Examples)

Previous Article: Kubernetes: How to Share Secrets Between Namespaces

Series: Kubernetes Tutorials

DevOps

You May Also Like

  • How to reset Ubuntu to factory settings (4 approaches)
  • Making GET requests with cURL: A practical guide (with examples)
  • Git: What is .DS_Store and should you ignore it?
  • NGINX underscores_in_headers: Explained with examples
  • How to use Jenkins CI with private GitHub repositories
  • Terraform: Understanding State and State Files (with Examples)
  • SHA1, SHA256, and SHA512 in Terraform: A Practical Guide
  • CSRF Protection in Jenkins: An In-depth Guide (with examples)
  • Terraform: How to Merge 2 Maps
  • Terraform: How to extract filename/extension from a path
  • JSON encoding/decoding in Terraform: Explained with examples
  • Sorting Lists in Terraform: A Practical Guide
  • Terraform: How to trigger a Lambda function on resource creation
  • How to use Terraform templates
  • Understanding terraform_remote_state data source: Explained with examples
  • Jenkins Authorization: A Practical Guide (with examples)
  • Solving Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap
  • Understanding Artifacts in Jenkins: A Practical Guide (with examples)
  • Using Jenkins with AWS EC2 and S3: A Practical Guide