{"id":21507,"library":"kubernetes-validate","title":"kubernetes-validate","description":"Validates Kubernetes resource definitions (YAML/JSON) against the schemas from the Kubernetes OpenAPI specification. Current version 1.35.0 supports Kubernetes 1.35. Supports Python >=3.7. Released approximately twice a year to match Kubernetes minor versions.","status":"active","version":"1.35.0","language":"python","source_language":"en","source_url":"https://github.com/willthames/kubernetes-validate","tags":["kubernetes","validation","yaml","json-schema","k8s"],"install":[{"cmd":"pip install kubernetes-validate","lang":"bash","label":"pip install"}],"dependencies":[{"reason":"Required for parsing YAML files.","package":"PyYAML","optional":false},{"reason":"Used for JSON Schema validation.","package":"jsonschema","optional":false},{"reason":"Required for schema referencing in newer versions (v1.29+).","package":"referencing","optional":false}],"imports":[{"note":"No direct 'validator' symbol exists; use 'validate' function.","wrong":"from kubernetes_validate import validator","symbol":"validate","correct":"from kubernetes_validate import validate"},{"note":"validation_failures is in the utils module, not top-level.","wrong":"from kubernetes_validate import validation_failures","symbol":"validation_failures","correct":"from kubernetes_validate.utils import validation_failures"}],"quickstart":{"code":"from kubernetes_validate import validate\nimport yaml\n\nwith open('deployment.yaml') as f:\n    resource = yaml.safe_load(f)\nfailures = validate(resource, 'apps/v1', 'Deployment', '1.35')\nif failures:\n    for f in failures:\n        print(f)\nelse:\n    print('Resource is valid')","lang":"python","description":"Validates a Kubernetes YAML resource against the schema for a specific API version and Kubernetes version."},"warnings":[{"fix":"Pin version: pip install 'kubernetes-validate<1.29'","message":"kubernetes-validate v1.29.0 removed support for Kubernetes v1.20 and v1.21. If you rely on those versions, pin to v1.28.1 or earlier.","severity":"breaking","affected_versions":">=1.29.0"},{"fix":"Update any custom schema files to the new format or use the bundled schemas.","message":"From v1.29.0, the JSON schemas changed completely to use a newer schema version, requiring the 'referencing' library. Old schema files may not be compatible.","severity":"breaking","affected_versions":">=1.29.0"},{"fix":"Use 'if failures:' or 'if len(failures) > 0' to detect validation errors.","message":"The validate function returns an empty list (not None) on success. Checking 'if not failures:' works, but comparing to None will fail.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run: pip install kubernetes-validate","cause":"Package name has an underscore, but pip installation uses 'kubernetes-validate' (hyphen).","error":"ModuleNotFoundError: No module named 'kubernetes_validate'"},{"fix":"Ensure the resource dictionary has the standard Kubernetes fields, e.g., from yaml.safe_load of a valid manifest.","cause":"The input resource dict does not contain 'apiVersion', 'kind', or 'metadata'. The validate function requires these keys.","error":"KeyError: 'apiVersion'"},{"fix":"Use 'from kubernetes_validate import validate' and call 'validate(...)' which returns a list of failures.","cause":"validation_failures is a class, not a function. The correct usage is to instantiate it or use the validate function directly.","error":"kubernetes_validate.utils.validation_failures object has no attribute '__iter__'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}