Display completed Kubernetes ConfigMap

9/13/2021

I've deployed the following ConfigMap with my Kubernetes DameonSet resource:

apiVersion: v1
kind: ConfigMap
metadata:
  name: fluentd-config
  namespace: fluentd
data:
  source: "#{ENV['MY_SOURCE']}"

How can I find out what source evaluates to when my DameonSet is deployed?

I've tried the following but it doesn't help:

kubectl describe configmaps fluentd-config

The output only displays the templated ConfigMap:

Name:         fluentd-config
Namespace:    fluentd
Labels:       <none>
Annotations:  <none>

Data
====
source: "#{ENV['MY_SOURCE']}"
-- Johnny Metz
configmap
kubernetes

1 Answer

9/21/2021

By default you cannot do templating of kubernetes yaml manifest files. You would have to use tools like helm, there are many more for this.

To illustrate the issue, if you do kubectl create -f on the below file, it would not interpolate $HOME variable to /home/ps, a literal string $HOME would be assigned inhome-dir.

apiVersion: v1
data:
  home-dir: $HOME
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: my-data-1

However, if you would do this imperatively , you can get the variable interpolated.

kubectl create  cm my-data-2 --from-literal=home-dir="$HOME" --dry-run=client -o yaml
apiVersion: v1
data:
  home-dir: /home/ps
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: my-data-2

You can also do variable expansion as below:

cat << EOF |kubectl create -f -
apiVersion: v1
data:
  user-name: $USER
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: my-data-3
EOF
-- P....
Source: StackOverflow