Search code examples
gokubernetesknativeknative-serving

How to create the knative serving


I have written a custom resource as part of the deployment. As part of this in the reconcileKind function, I have written the logic to create pod as shown below using the Kubernetes APIs in Go itself.

Image

I would like to convert this to knative serving (instead of creating the POD which will be always running) so that I can make of KPA feature. I am aware of creating knative serving using the .yaml way. But I would like to create it by using the Kubernetes API itself. I did search in the official documentation, but everything explained was using the .yaml way.

So I'm curious whether can we achieve knative serving by directly using Kubernetes APIs?


Solution

  • How to create the knative serving using golang?

    You need to use the Go-client for Knative Serving, e.g. the client type - corresponding to the corev1.Pod that you used in your code.

    The Go client for Knative v1.Serving is in the Knative repository.

    Instead of CoreV1() in your code, you can use ServingV1() from the Knative Go client.

    But I would recommend to use Yaml manifests unless you have custom needs.