# Dynamic Declarative Object Management

**URL:** <https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372>\
**Category:** General Discussions\
**Created:** [May 17, 2019, 11:27am UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372 "2019-05-17T11:27:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertodonpedro](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/robertodonpedro/32/2898_2.png) [@robertodonpedro](https://discuss.kubernetes.io/u/robertodonpedro)\
**Post date:** [May 17, 2019, 11:27am UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/1 "2019-05-17T11:27:46Z")

</div>

Hi,  
with kubectl apply … deployments are defined in yaml files, which seems to be a very static approach.  
Basically I would like to dynamicallly create unique deployments per customer but based on the same deployment-yaml. Meaning I would need to pass eg. a customer id dynamically rather than defining everything in the yaml.  
Is there a way to accomplish this?  
Thx Robert

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [May 17, 2019, 12:13pm UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/2 "2019-05-17T12:13:04Z")

</div>

Have you looked into Helm at all? I think that might be a good fit for this case. [https://helm.sh/](https://helm.sh/)

---

<div class="post-metadata">

**Author:** ![robertodonpedro](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/robertodonpedro/32/2898_2.png) [@robertodonpedro](https://discuss.kubernetes.io/u/robertodonpedro)\
**Post date:** [May 17, 2019, 1:41pm UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/3 "2019-05-17T13:41:34Z")

</div>

Well, as far a I understand Helm its not declarative, isn’t it?  
However, my final goal is to kick off this dynamic deployment creation through a PHP Client using the REST API. I think Helm has no libraries available to support this easily, right?

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [May 18, 2019, 12:12am UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/4 "2019-05-18T00:12:25Z")

</div>

Helm can be a little bit of both. You’d provide it a template (Chart) and it would populate that with a values file. So if you needed a common template that would be populated by changing variables it would fit nicely.

Each deployment (chart + values) would be it’s own unique deployment. The values could also be passed as args to the helm client ( `--set my.value=this`). I think that might work for your scenario.

Here’s the guide for developing charts which might give you a better idea of what it does, [https://helm.sh/docs/chart\_template\_guide/#the-chart-template-developer-s-guide](https://helm.sh/docs/chart_template_guide/#the-chart-template-developer-s-guide)

---

<div class="post-metadata">

**Author:** ![robertodonpedro](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/robertodonpedro/32/2898_2.png) [@robertodonpedro](https://discuss.kubernetes.io/u/robertodonpedro)\
**Post date:** [May 18, 2019, 6:18pm UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/5 "2019-05-18T18:18:12Z")

</div>

Yes, but Helm seems to be not declarative though. Eg. if you look a the helm deployments you won’t find `kubectl.kubernetes.io/last-applied-configuration` annotations there.  
The helm developer guide covers more the templates than the external available apis.  
So right now I tend to build on the latest kubernetes stack rather than on an additional layer.  
Therfore I still would be interested to learn if I can make use of an `kubectly apply` based api and pass dynamically created arguments along with yaml files?

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [May 18, 2019, 7:57pm UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/6 "2019-05-18T19:57:11Z")

</div>

Ahh ya, if you’re relying on `kubectl` things would be different. Helm does keep track of its deployments and you can see things via the `helm history` command. If you want to keep things going through `kubectl` you can use Helm strictly for templating using the `helm template` . command. This will do the template merging and generate the desired yaml files.

I am assuming you are storing a template base yamls and wanting to merge in the dynamic vars through to that.

There may be a workflow you can get going through that. The next closest native tool in `kubectl` I can think of is `kustomize`.

---

<div class="post-metadata">

**Author:** ![robertodonpedro](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/robertodonpedro/32/2898_2.png) [@robertodonpedro](https://discuss.kubernetes.io/u/robertodonpedro)\
**Post date:** [May 20, 2019, 8:47am UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/7 "2019-05-20T08:47:47Z")

</div>

No, that’s not what I need. `kustomize` just applies overlays which are still stored in static yaml files.  
What I want is to apply the **dynamically** created content of a eg. a `kustomization.yaml` through a REST API. without the obligation to store it in the filesystem in advance.  
I consider to pass information which uniquely relates all objects to customers, eg. by  
commonLabels:  
customer: MyFirstCustomer  
```  
But although `kubectl` uses the kubernetes APIs internally , it seems that it contains a lot of client logic, which makes it hard to simply use the same API for this purpose.

I just came accross the [Server Side Apply](https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply), maybe that’s the right approach for my purpose??? It would be great if there were any examples available for the relevant APIs…

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [May 20, 2019, 12:18pm UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/8 "2019-05-20T12:18:16Z")

</div>

I can’t think of anything else off the top of my head that doesn’t rely on having files somewhere. There might be something out there though.

Sorry I couldn’t be of more help. Good luck!

---

<div class="post-metadata">

**Author:** ![robertodonpedro](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/robertodonpedro/32/2898_2.png) [@robertodonpedro](https://discuss.kubernetes.io/u/robertodonpedro)\
**Post date:** [May 20, 2019, 2:06pm UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/9 "2019-05-20T14:06:40Z")

</div>

No problem at all and thanks for your assistance. I will do some more research, however maybe I will have to stick with files anyway.

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [May 20, 2019, 2:09pm UTC](https://discuss.kubernetes.io/t/dynamic-declarative-object-management/6372/10 "2019-05-20T14:09:58Z")

</div>

If you find something let us know. I’m interested to hear what solution you find.
