Get all Deployments referencing given ConfigMap by the ConfigMap's name Suppose I have a ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
  name: london-tz-config
data:
  SERVER_TIMEZONE: &quot;Europe/London&quot;

I also have about 50 distinct Deployments. Let's say that 20 of them use the london-tz-config ConfigMap to set their environments, like this
  template:
    metadata:
      labels:
        app: echo-app
    spec:
      containers:
        - name: echo-app-container
          image: ealen/echo-server:latest
          ports:
            - containerPort: 8080
          env:
            - name: SERVER_TIMEZONE
              valueFrom:
                configMapKeyRef:
                  name: london-tz-config    # Reference our ConfigMap here
                  key: SERVER_TIMEZONE

I don't know which Deployments use which ConfigMaps at any given time without manually inspecting the cluster.
Is there a way to ask Kubernetes to show me all Deployments that contain references to a given ConfigMap by its metadata.name attribute?
Either kubectl or the Kubernetes API would be okay.
You can use kubectl get -o json and parse the output using jq to iterate over the deployments, matching any desired configMapKeyRef.name and returning a uniq list of deployments.
This should work:
kubectl get deployments --all-namespaces -o json | jq -r '.items | map(select(.spec.template.spec.containers[]?.env[]?.valueFrom.configMapKeyRef.name == &quot;london-tz-config&quot; ) | .metadata.name) | .[]' | uniq