Skip to main content
Bumped by Community user
Source Link

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: "Europe/London"

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.