Intro
Kubernetes Extensible Admission Controllers are a powerful mechanism for enforcing policies and mutating resources before they are persisted. They allow cluster administrators to plug in custom logic via admission webhooks, but when things go wrong, they can block deployments, prevent Pod creation, or even degrade API server responsiveness. Troubleshooting these controllers requires a systematic approach that combines understanding of the admission control flow, ability to inspect webhook configurations, and skill in reading API server logs. This guide provides practical examples and commands to diagnose and recover from common failures.
A narrow, measurable pilot is recommended before deploying admission controllers broadly, as it allows local inspection and reduces risk. This aligns with the principle that a clear process reduces rework and accelerates producing reliable configurations.
Environment and Version Inventory
Before troubleshooting, gather information about the Kubernetes cluster and the admission controllers in use. This includes the Kubernetes version, the API server configuration, and the specific webhooks configured.
Prerequisites:
- Access to the cluster with sufficient permissions to view ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects.
- Ability to read logs from the kube-apiserver pod or process.
- The kubectl command-line tool configured for the cluster.
- Knowledge of the webhook service endpoints and their expected behavior.
Inventory Commands
Run the following commands to establish a baseline:
- Check Kubernetes version:
kubectl version --short
Expected output includes client and server version, e.g., Server Version: v1.25.3.
- List admission webhook configurations:
kubectl get validatingwebhookconfigurations, mutatingwebhookconfigurations
This lists all webhook configurations. Note any that are failing or suspect.
- Get details of a specific webhook configuration:
kubectl get validatingwebhookconfiguration <name> -o yaml
Examine the webhooks array for each webhook's clientConfig, rules, and failurePolicy.
- Check API server pods (if using static pods or managed control plane):
kubectl get pods -n kube-system | grep kube-apiserver
For self-managed clusters, locate the API server pod name for log retrieval.
Topology Considerations
- Identify whether webhooks point to in-cluster services or external URLs.
- For in-cluster services, verify the service exists and has endpoints.
- For external URLs, ensure network connectivity from the API server.
Example inventory table:
| Component | Value |
|---|---|
| Kubernetes version | 1.25.3 |
| ValidatingWebhookConfiguration | pod-policy.example.com |
| MutatingWebhookConfiguration | sidecar-injector.example.com |
| Webhook service | webhook-service in namespace webhook |
| Failure policy | Fail |
This inventory establishes a baseline for troubleshooting.
Safe Configuration Path
Admission webhooks can be dangerous because a misconfiguration can block all resource creation or mutation. It is important to adopt a safe configuration path that limits blast radius and allows quick rollback.
Scoped Implementation Choices
- Use
failurePolicy: Ignoreduring initial deployment: This ensures that if the webhook is unreachable, the API server will ignore the failure and allow the request. Once stability is confirmed, you can switch toFailfor strict enforcement.
Example snippet from a webhook configuration:
failurePolicy: Ignore
- Limit rules to specific resources or namespaces: Instead of applying the webhook cluster-wide, use
namespaceSelectororobjectSelectorto target a test namespace or specific labels.
Example:
namespaceSelector:
matchLabels:
admission-webhook: enabled
- Set
timeoutSecondsappropriately: The default is 10 seconds; adjust based on webhook latency. - Use
sideEffects: Noneif the webhook has no side effects: This is required for dry-run support and helps in testing. - Test in a non-production cluster first: Always deploy the webhook in a staging environment.
Configuration Change Procedure
To modify a webhook configuration safely, use kubectl edit or apply a YAML file with version control.
Example of updating failurePolicy to Ignore for a validating webhook:
kubectl patch validatingwebhookconfiguration pod-policy.example.com --type='json' -p='[{"op": "replace", "path": "/webhooks/0/failurePolicy", "value": "Ignore"}]'
Expected output: validatingwebhookconfiguration.admissionregistration.k8s.io/pod-policy.example.com patched.
Always keep a backup of the original configuration for rollback.
Verification and Diagnostics
When troubleshooting, you need to verify that the webhook is being called, the endpoint is responding correctly, and the API server is behaving as expected.
Observable Checks
Retrieve logs from the kube-apiserver pod. On a managed cluster, you may need to use cloud provider logging.
- Check API server logs for webhook errors:
kubectl logs -n kube-system kube-apiserver-<node-name> | grep -i webhook
Look for lines containing failed calling webhook, webhook timeout, or x509: certificate signed by unknown authority.
Example log snippet:
E0201 12:34:56.789012 1 dispatcher.go:167] failed calling webhook "pod-policy.example.com": Post "https://webhook-service.webhook.svc:443/validate?timeout=10s": dial tcp 10.0.0.1:443: connect: connection refused
This indicates the webhook service is unreachable.
From within the cluster, use a pod with curl to send an admission review request.
- Test the webhook endpoint directly:
kubectl run curl-test --image=curlimages/curl -i --tty --rm -- sh
curl -k -X POST https://webhook-service.webhook.svc:443/validate -H "Content-Type: application/json" -d '{"apiVersion":"admission.k8s.io/v1","kind":"AdmissionReview","request":{"uid":"test"}}'
Check the response; it should be a valid AdmissionReview with an allowed field.
Use kubectl apply --dry-run=server to test if a resource would be admitted without actually creating it.
- Verify webhook configuration with dry-run:
kubectl apply -f pod.yaml --dry-run=server
If the webhook blocks the request, you'll see an error like denied by admission webhook.
Webhooks must use HTTPS. If the API server cannot verify the server certificate, requests fail. Look for certificate errors in logs. Ensure the CA bundle in the webhook configuration matches the serving certificate.
- Check certificates:
Some webhooks generate events on the resources they affect.
- Use
kubectl describefor events:
Expected Results
- API server logs show successful webhook calls with HTTP 200 responses.
- Direct endpoint test returns an AdmissionReview response with
"allowed": trueor appropriate patch. - Dry-run of valid resources succeeds; invalid resources are rejected with clear message.
Failure Modes and Recovery
Common failure modes include webhook service unavailability, certificate issues, timeout, and misconfigured rules causing unintended blocking. Recovery requires quick action to restore cluster functionality.
Failure Mode 1: Webhook service down or unreachable
- Symptom: API server logs show
connection refusedortimeout; all requests to affected resources fail iffailurePolicy: Fail. - Recovery:
- Temporarily set
failurePolicy: Ignoreto unblock requests:
kubectl patch validatingwebhookconfiguration <name> --type='json' -p='[{"op": "replace", "path": "/webhooks/0/failurePolicy", "value": "Ignore"}]'
- Fix the underlying service (restart pods, fix service selector).
- Once service is healthy, revert to
Failif required.
Failure Mode 2: Certificate problems
- Symptom: Logs show
x509: certificate signed by unknown authorityortls: failed to verify certificate. - Recovery:
- Update the
caBundlefield in the webhook configuration with the correct CA certificate. - Ensure the webhook server uses a certificate valid for its service DNS name.
- Use a certificate management tool like cert-manager to automate.
Failure Mode 3: Webhook timeout
- Symptom: Logs show
context deadline exceededortimeout. - Recovery:
- Increase
timeoutSecondsin the webhook configuration (max 30). - Optimize webhook processing.
Failure Mode 4: Webhook blocking all resources due to broad rules
- Symptom: Even unrelated resources are denied.
- Recovery:
- Narrow the rules or use
namespaceSelectorto limit scope. - If critical, delete the webhook configuration temporarily:
kubectl delete validatingwebhookconfiguration <name>
This removes the webhook entirely; ensure you can recreate it later.
Rollback Strategies
- Maintain versioned backups of webhook configurations.
- Use GitOps to track changes and enable quick revert.
- Test rollback procedures in staging.
Recovery Checks: After recovery, verify that resource creation succeeds and that the webhook is functioning as intended for targeted resources.
Operations Checklist
Use this checklist for ongoing operations and review of admission controllers:
- [ ] Monitor API server logs for webhook errors regularly.
- [ ] Ensure webhook services have high availability and proper resource limits.
- [ ] Renew certificates before expiry.
- [ ] Review webhook configurations for least privilege and scope.
- [ ] Test webhook behavior in staging before changes.
- [ ] Document failure policies and rollback procedures.
- [ ] Set alerts for webhook failure rates.
- [ ] Perform periodic chaos testing to validate resilience.
Example Monitoring Query (if using Prometheus):
rate(apiserver_admission_webhook_admission_duration_seconds_count{name="pod-policy.example.com"}[5m]) > 0
This checklist ensures reliable operation and quick recovery.
Conclusion
Troubleshooting Kubernetes Extensible Admission Controllers requires a methodical approach: inventory the environment, configure safely with failure policies and scoping, verify through logs and dry-runs, and recover from failures with quick rollback actions. By following the practical steps and checklist in this guide, teams can minimize downtime and maintain cluster stability. Start with a narrow, measurable pilot and expand gradually, always keeping observability and rollback plans in place. The next verified steps after addressing immediate issues are to implement monitoring, automate certificate management, and document operational runbooks.