Is there an include directive for Kubernetes yaml resource definitions?

2/26/2018

Consider the following ConfigMap definition, in, say, foo.yml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: foo-data
data:
  foo.json: |-
    {
      "foo": "foo",
      "bar": 42
    }

Is there a way to load the foo.json data from an external file, instead of inlining it in the template? It would be nice if I could put the data in a file foo.json next to foo.yml, reference it somehow, and have K8s figure it out when I apply the template.

Is that possible? How?

If not, is the feature on the roadmap?

-- Tomas Aschan
kubernetes

3 Answers

2/26/2018

I have seen only one in-cluster templating tool:

https://github.com/kelseyhightower/konfd

However, it does not do what the question is asking for.

Generally speaking the tooling world seems mostly focused on doing resource template rendering out of cluster, probably to reduce complexity when it comes to resource lifecycle.

Maybe the thing to do is write a simple shell script to take a json file and spit out a ConfigMap "wrapper" for it, which can then be piped to kubectl.

-- Jonah Benton
Source: StackOverflow

9/19/2018

You can create a configmap from a file:

kubectl create configmap foo-data --from-file=foo.json

See details in the docs: https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/

h/t https://stackoverflow.com/a/50991357/1017361

-- Cary
Source: StackOverflow

9/24/2019

Afaik there is no build-in templating as for now but you can use ansible templating capabilities with k8s yaml files saute or together with e.g. k8s plugin.

Works like a charm :)

-- bazeusz
Source: StackOverflow