2

I'm using a MutatingWebhookConfiguration in order to inject a sidecar app into my pod. This works fine, but I'd like now to be able to create a new service for this sidecar. Anyway my question is a bit broader: can we from a webhook create other objects or are we limited to mutate only the request object ?

Do you have any solution ?

benjamin.d
  • 2,801
  • 3
  • 23
  • 35

1 Answers1

1

Kubernetes doesn't have such a mechanism: Mutating Webhooks for an outside object or manifest.

In essence, you can concatenate as many objects/manifests in a Kubernetes config file. So, you could have a manifest that injects the sidecar component together with the creation of a service. You can separate the manifests using a --- line, which signals the start of a new document in YAML. Then apply the whole configuration files with:

$ kubectl apply -f <config-file>.yaml

More background on this answer.

Rico
  • 58,485
  • 12
  • 111
  • 141
  • But my webhook is hooked to the `apps`and `deployment`types. How can I do this for a whole manifest ? – benjamin.d Sep 02 '19 at 08:02
  • I tried to add a document separtor `---` and a new object in the manifest, but my hook only gets called for the individual objects. Maybe I did not get what you meant. – benjamin.d Sep 02 '19 at 08:47
  • That's the way it's supposed to work. The webhook will only work on one object. Adding another manifest will just create the new object afterward. That's a poor boy's workaround. There's no real way to mutate a separate object with a mutating admission controller. – Rico Sep 02 '19 at 14:53