How to patch a ConfigMap in Kubernetes

后端 未结 4 1078
北海茫月
北海茫月 2021-01-01 23:34

Kubernetes ships with a ConfigMap called coredns that lets you specify DNS settings. I want to modify or patch a small piece of this configuration

相关标签:
4条回答
  • 2021-01-02 00:11

    you should try something like this:

    kubectl get cm some-config -o yaml | run 'sed' commands to make updates | kubectl create cm some-config -o yaml --dry-run | kubectl apply -f - 
    
    0 讨论(0)
  • 2021-01-02 00:16

    As ConfigMaps are used to mount configuration files to Pod, it seems like this is what you are looking for. ConfigMaps inside of containers will update automatically if the underlying ConfigMap or Secret is modified.

    You can specify configMap location:

    configMapVolume(mountPath: '/etc/mount3', configMapName: 'my-config'),

    Update:

    Ok, I guess this does not solve your issue. Other thing that comes to my mind is kubectl create configmap with a pipe to kubectl replace So the whole command would look like this:

    kubectl create configmap NAME --from-file file.name -o yaml --dry-run | kubectl replace -f -

    Note that this replaces whole file, so just replace should work too.

    0 讨论(0)
  • 2021-01-02 00:21

    This will apply the same patch to that single field:

    kubectl patch configmap/coredns \
      -n kube-system \
      --type merge \
      -p '{"data":{"upstreamNameservers":"[\"1.1.1.1\", \"1.0.0.1\"]"}}'
    
    0 讨论(0)
  • 2021-01-02 00:35

    you can edit it using vi as follows:

        kubectl edit cm -n kube-system coredns 
    

    or you can export it to apply any changes using kubectl get cm -n kube-system -o yaml --export then use kubectl apply -f fileName.yaml to apply your changes

    0 讨论(0)
提交回复
热议问题