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
Have you looked into Helm at all? I think that might be a good fit for this case. https://helm.sh/
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?
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
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?
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
.
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, maybe that’s the right approach for my purpose??? It would be great if there were any examples available for the relevant APIs…
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!
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.
If you find something let us know. I’m interested to hear what solution you find.