# See if a specific resource exists in a Kubernetes namespace

I want to have a function that checks to see if a certain resource (deployment, job, cronjob etc) exist in a namespace. Using the Kubernetes Python client, I can create a boolean function (using deployments as a concrete example).

from kubernetes import client, config

def deployment_exists(name, namespace="default"):
client = client.AppsV1Api()
try:

Is there a way to achieve the same without relying on the ApiException explicitly?
• From the return statements it seems like this is actually inside a function. If that is the case please include the whole function for context. – Graipher Feb 13 at 7:53