0

I have a setup where I have multiple configmaps (with a common prefix). How do I edit all (or some) of them using a single command? Use case is, I have a common field in all of them which I want to edit.

I tried kubectl edit configmap prefix* and kubectl edit configmap prefix.*. Didn't work.

Shubhzgang
  • 322
  • 2
  • 9
  • There is no such command or way to edit the multiple config files using a common key name in kubectl but as per this [gitlink](https://github.com/kubernetes-sigs/kustomize/issues/1028) we can use kustomize which is a configuration tool that allows you to customize Kubernetes resources by using overlays, rather than modifying the original resources directly. Refer to this [blog](https://opensource.com/article/21/6/kustomize-kubernetes) by Redhat for information on kustomize and modifying the config files. – Hemanth Kumar Jul 26 '23 at 09:44
  • If you wish to update a single config file then refer to this [SO](https://stackoverflow.com/questions/49989943/kubectl-update-configmap) which has multiple solutions. – Hemanth Kumar Jul 26 '23 at 09:45
  • Please let me know whether the shared info was helpful. I am happy to assist if you have any further queries. – Hemanth Kumar Jul 28 '23 at 03:30
  • Are the above comments helped you ? I am happy to assist if you have any further queries – Hemanth Kumar Aug 01 '23 at 03:59

1 Answers1

0

Kubernetes does not have a built in feature to achieve this, however you can use a script like below to edit multiple configmaps.

#!/bin/bash

configmaps=("configmap1" "configmap2" "configmap3")

for cm in "${configmaps[@]}"; do kubectl edit configmap "$cm" done