1

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?

Jonas
  • 121,568
  • 97
  • 310
  • 388
coders
  • 719
  • 1
  • 11
  • 35

1 Answers1

1

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.

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • Thanks a lot for responding. if i use the yaml manifest, how can i execute that yaml file in the reconcileKind so that it will execute. Can you please guide me? – coders Oct 05 '20 at 16:23
  • Also with Go client which is the function? i quite didn't get it. – coders Oct 05 '20 at 16:24
  • ooh got it. Thanks. Can you please explain me wrt the yaml manifest way – coders Oct 05 '20 at 16:26
  • A hello-world using Yaml is here: https://knative.dev/docs/serving/samples/hello-world/helloworld-go/#recreating-the-sample-code – Jonas Oct 05 '20 at 16:27
  • i mean still we need to execute yaml separately right? this won't be the if i write using api.. when i execute the main application all the logic under ReconcileKind will execute and create.. – coders Oct 05 '20 at 16:45
  • @coders yes, if you are writing a custom controller, you should use the Go client, that is a valid use case. – Jonas Oct 05 '20 at 17:02
  • I will try this out. I mean no change in the code, instead of KubeClientSet.CoreV1(), use KubeClientSet.ServingV1() right? – coders Oct 06 '20 at 05:17
  • you need to import the library, it is another clientset (see my link) and use `ServingV1()` and its types instead of Pods. – Jonas Oct 06 '20 at 06:07
  • yes, before doing this i need to define yaml manifest using serving API https://knative.dev/docs/reference/api/serving-api/#serving.knative.dev/v1.Service – coders Oct 06 '20 at 10:22