Webhooks in kubernetes - kubernetes

I have a requirement to watch for PVC creation events and handle it before forwarding to actual Kubernetes controller for processing the PVC creation. I went through many docs and feel webhooks can be used for achieving this. But would like to get expert opinion on the approach and best practices.

Related

Any smart way to make REST call to Kubernetes services to get readiness/liveness status

Need a suggestion here.
We're using K8S v1.20 and running plenty of services on it, we are looking for the best way to get a readiness check of each of those services. I read about https://kubernetes.io/docs/reference/using-api/health-checks/#individual-health-checks but this is only available in v1.23.
There seems no REST API available, https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/
We're currently maintaining the endpoints in repo and do curl one after another, but we want to reduce the overhead of maintaining the endpoint list.
Any suggestion is highly appreciable.

How to know which custom controller handle a certain CRD

With CRD we can extend the functionality of kubernetes, but how could I know which controller handle a certain CRD, I mean I know there is a CRD registered in my kubernetes named foo but how could I know which controller/pod do the reconcile for it?
There is no way of knowing just by looking at the CRDs. Several different controllers could be watching the same CRD, it's not like there is a 1-1 relationship.
If you really need to know, there would be ways of figuring this out, like enabling the audit log and inspecting the calls received by the k8s api.

Pod route in Kubernetes

Is there any possibility to create a service which is able to route traffic to selected pod(not pod group).
Example: myservice.whatever:1000/podNameAppName to route to custom pod ?
As mentioned by Alassane Ndiaye for internal routing.
In addition if this question is related to the external requests you should create more advanced application design.
Please take a look for ADC concept like NGINX ADC, ISTIO Design Pattern and ADC overview.
Basically this task should be implemented at higher level using all benefits from L7 loadbalncing support.
Please take a look also for K8s concepts
Hope this help.

How to create a replicaset through a custom resource?

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.

What is a sidecar in the context of microservices?

I'm currently looking through an Istio and Kubernetes talk and mention the management of services along with the use of sidecars. I'm not sure what that is.
I think of them as helper containers. A pod can have 1 or more containers. A container should do only one thing, like a web server or load balancer. So if you need some extra work to be done inside the pod, like github sync or data processing, you create an additional container AKA sidecar.
The best (original?) description of the "Sidecar"-pattern I know of is from Brendan Burns and David Oppenheimer in their publications on "Container Patterns for Distributed Systems".
Check out the paper + slides here:
https://www.usenix.org/conference/hotcloud16/workshop-program/presentation/burns
There are other design patterns too, like "Ambassador" or "Adapter". I'm not really sure whether the istio implementation is really a sidecar in the way they describe it there, but anyway I think that's where the term originates from.