Skip to content

Kyverno: reading admission webhook … denied the request

Kubernetestested on RKE2 v1.37.2, Kyverno v1.20.0

Kyverno hooks into the API server as an admission webhook. When a policy rejects something, the message starts with admission webhook "…kyverno.svc…" – that is how you recognize the sender. After it come the policy name and its message.

Symptom

kubectl apply -f web.yaml
Error from server: error when creating "web.yaml": admission webhook
  "vpol.validate.kyverno.svc-fail" denied the request: Policy require-team-label
  failed: Jedes Deployment braucht das Label team.

"-fail" in the webhook name means failurePolicy: Fail. The object is never created. The policy message here is German: "Every Deployment needs the label team."

Diagnosis

Look at the policy from the message in the cluster – a ValidatingPolicy here.

kubectl get vpol
NAME                 AGE   READY
require-team-label   3s    true

Causes

ValidationThe object doesn't satisfy the rule

In the course the Deployment lacks the label team in its own metadata. The label in the Pod template does not count for this rule.

Only Pods checkedDeployment accepted, but 0/1

If the policy only checks Pods, the Deployment is accepted and the ReplicaSet fails to create its Pods. Normally Kyverno generates matching rules for Deployments from Pod rules (autogen); an objectSelector turns that off – status.autogen is then empty.

kubectl -n tag12 events --types=Warning | grep ReplicaSet/api | tail -1
kubectl get vpol require-memory-limit -o jsonpath='{.status.autogen}{"\n"}'
0s (x11 over 5s)   Warning   FailedCreate   ReplicaSet/api-594fdbd485   Error creating:
  admission webhook "vpol.validate.kyverno.svc-fail-a5928e6d" denied the request:
  Policy require-memory-limit failed: Jeder Container braucht ein Memory-Limit.
{}

failed calling webhookThe webhook is unreachable

A different message: the Service kyverno-svc has no endpoints. Because of failurePolicy: Fail, the API server rejects every matching change instead of letting it through.

kubectl -n tag12 run t --image=busybox:1.37 -- sleep 5
Error from server (InternalError): Internal error occurred: failed calling webhook
  "mpol.validate.kyverno.svc-fail": failed to call webhook: Post
  "https://kyverno-svc.kyverno.svc:443/mpol/add-run-as-non-root?timeout=10s": no
  endpoints available for service "kyverno-svc"

Fix

Make the object comply with the policy – here the label goes into the Deployment's metadata – and apply again.
sed -i 's/namespace: tag12}/namespace: tag12, labels: {team: shop}}/' web.yaml
kubectl apply -f web.yaml
kubectl -n tag12 rollout status deploy/web
kubectl -n tag12 get deploy web
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
web    1/1     1            1           5s
▶
Break it yourself and find it – free
Debugging Kubernetes, day 12: rejections, mutations and failed webhooks caused by Kyverno – with a drill to reproduce each one.
Go to day 12 →

FAQ

How do I know Kyverno rejected the request?

By the webhook name in the message: it contains kyverno.svc, followed by a suffix like -fail. After it come policy and message.

Why do I see no error on apply, but no Pods either?

Then the policy only checks Pods. The event is on the ReplicaSet; kubectl events --types=Warning shows it.

Related error patterns

More