Whenever the deployment has been created needs to trigger a custom function or webhook. Does Kubernetes provide any option to do this?
Custom Resources are an extension to the Kubernetes API. Just having them standalone is not going to do anything functionally for you. If you need to perform a specific action upon change or deployment or bare existence of a given custom resource, you will need a custom controller that does that.
One of the possible implementations is an Operator. I specifically mention that, as it is fairly easy to create the controller alongside the custom resource definition using Operator SDK. However you can just create a custom resource definition and deploy a custom controller.
On a closing note: there are other ways your question is very broadly formulated so there is a vast variety of ways to answer, and this is just one option.
Related
I have a complex kubernetes customer resource definition. I want to generate a valid custom resource object from the definition and then replace some values with mine. This is for quick testing purposes.
Instead of creating a yaml file from scratch, I'd like to use a tool to automatically generate it. Like what kubebuilder does when creating an API (put sample objects under config/samples).
Question: Is there any existing tool for this purpose?
Generally, for generating custom Kubernetes objects based on template there are two solutions:
Kustomize
Helm
Both of them have a good documentations with examples - you can find them here for Kustomize and here for Helm.
For better understanding what exactly are they used for and what are differences between them I suggest reading this article and this StackOverFlow answer.
We are in the process of designing a cloud native application that needs a control loop to keep its objects (few thousands) in desired state. Other than implementing the application as a set of Kubernetes CRDs, we are wondering whether there are any other open source alternatives. If you have developed your own custom implementation of control loop, can you please let us know the reasons behind that decision (as opposed to using Kubernetes CRDs)?
Your description seems to fit with the purpose of a CRD controller.
Check the Kubebuilder framework, you can bootstrap a controller quickly and you will just need to implement the reconcile loop
I'm writing a custom controller that would listen to a CR I defined and update/create other resources (ones defined by Istio). All the examples out there show either how to handle native resources or custom ones created in the same package. But the resources I want to manage already exist and are registered in the cluster. So what I'm failing to understand is how to create or update them in Go code without describng them with my own types.
So I fgured out there is no way to do this without actually defining schemas for all the objects I want to manage in my own code.
I suppose it would be a good idea for anyone providing open source CRDs to also provide a go library that defines the types for them
I want to create a custom resource that is able to create a replicaset under a certain event. What is the best way to accomplish this?
Note that I am aware of deployment, but deployment does not meet my intended use cases.
Seems like you might be looking into building something that would suit more or less the operator pattern.
https://coreos.com/operators/
https://coreos.com/blog/introducing-operators.html
https://github.com/coreos/prometheus-operator
Generaly you need to watch on some resources including your custom ones with kube client and act based on events propagated from kube API.
I have found couple of references to the "TryAddStateSerializer" method but it appears to be deprecated, and the examples provided don't seem to work anyway including this one GitHub Azure content.
How an I supposed to register my Custom serializer?
TryAddStateSerializer is currently the only way to do it. The API may change in the future but it is safe to use today.