Validating a Webhook
We have learned that the mutating webhook essentially allows the modification of Kubernetes objects. The other kind of webhook is called a validating webhook. As the name suggests, this webhook does not allow any change in the Kubernetes objects; instead, it works as a gatekeeper to our cluster. It allows us to write code that can validate any Kubernetes object being requested and allow or reject the request based on the conditions that we specify.
Let's understand how this can be helpful using an example. Let's assume that our Kubernetes cluster is used by many teams, and we want to know which Pods are associated with which teams. One solution is to ask all the teams to add a label on their Pod (for example, a label with the key as teamName
and the name of the team as the value). As you can guess, it is not a standard Kubernetes feature to enforce a set of labels. In this case, we would need to create our own logic to disallow Pods that do not have...