23

I am trying to delete a configmap from a k8s namespace .. i created the configmap using the command below

kubectl -n namespacename create -f configmap.yaml

checking the k8s cheat sheet https://kubernetes.io/docs/reference/kubectl/cheatsheet/ i didn't find anything related .. kindly advise how to do that ?

Hany Habib
  • 1,377
  • 1
  • 10
  • 19

4 Answers4

58

To delete configmap using configmap name:

# kubectl delete configmap  <configmap-name>  -n  <namespace-name> 
$ kubectl delete configmap    my-cofigmap     -n   namespacename 

To delete configmap using configmap yaml file:

# kubectl delete -f <file-directory> -n <namespace-name>
$ kubectl delete -f  configmap.yaml  -n  namespacename
Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46
  • yah that works :) thanks .. small question if i deleted it while its used will it affect the running pods ? – Hany Habib Dec 12 '19 at 09:18
  • 2
    @HanyHabib The data of the ConfigMap still stays mounted in the running Pods. However, if a Pod is recreated, it will not be able to find the ConfigMap and an error will result. – weibeld Dec 12 '19 at 09:23
5

You can delete a configMap by it's name. If you are unsure you can check the configMaps within a namespace by using:

kubectl get configmap -n namespacename`

once you have them you can run a delete command:

kubectl delete configmap <configmapname> -n namespacename
Amal Thundiyil
  • 307
  • 1
  • 4
  • 9
Fermin
  • 34,961
  • 21
  • 83
  • 129
1

Should work this way:

kubectl delete configmap <configmap-name> -n <namespace-name>

Your configmap's name should be defined in your configmap.yaml file.

1

Easiest way if you created the ConfigMap with a YAML file is to delete it by referencing the YAML file as well:

kubectl delete -n <namespacename> -f configmap.yaml
weibeld
  • 13,643
  • 2
  • 36
  • 50