Automate Proxy Injection in EKS Fargate with Kyverno
In a world where cloud-native applications need to communicate securely and efficiently, managing proxy settings can become a cumbersome task. Manually adding proxy environment variables to each container in your deployment manifests is not only error-prone but also time-consuming. Automating this process with Kyverno allows you to enforce consistent proxy settings across your pods, enhancing security and simplifying your deployment workflow.
Kyverno operates as a mutating admission webhook within your Kubernetes cluster. When a pod creation request is made, the API server sends an AdmissionReview to Kyverno. If the pod's namespace is labeled with proxy-injection: enabled, Kyverno injects the necessary HTTPS_PROXY, HTTP_PROXY, and NO_PROXY environment variables into every container and init container at admission time. This means that your applications will start with the correct proxy settings already in place, allowing them to route outbound calls through the corporate proxy without additional configuration. The failurePolicy: Ignore setting ensures that pod scheduling is not blocked if the webhook is temporarily unavailable, maintaining your deployment's reliability.
In production, ensure that your Fargate profiles are correctly configured to match CoreDNS, Kyverno, and any other pods you schedule. Be aware that while CIDR ranges in NO_PROXY are honored by some clients, others like curl and libcurl may not behave as expected. This can lead to unexpected behavior if your applications rely on these tools for outbound communication. Always verify your proxy settings and test your applications thoroughly to avoid connectivity issues.
Key takeaways
- →Leverage Kyverno's MutatingPolicy to automate proxy injection for EKS Fargate pods.
- →Use the `proxy-injection: enabled` label to trigger automatic environment variable injection.
- →Configure `failurePolicy: Ignore` to prevent deployment issues during webhook outages.
- →Be cautious of NO_PROXY behavior across different clients, especially with curl and libcurl.
- →Ensure Fargate profiles are correctly set up to avoid pending states for your pods.
Why it matters
Automating proxy injection reduces manual errors and saves time, allowing your team to focus on building features rather than managing configurations. This consistency enhances security by ensuring all outbound traffic is routed through the corporate proxy.
Code examples
One MutatingPolicy of roughly 30 lines of YAML covers each pod in a labeled namespace, instead of three environment variables added by hand to each container in each deployment manifest.When NOT to use this
The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.
Want the complete reference?
Read official docsIndustry-standard certifications built by the people behind Linux and Kubernetes. Earn the CKA — the gold standard Kubernetes administrator cert. OpsCanary readers get 30% off year-round with code OPSCANARY3.
Get CKA certified →Mastering Ingress: The Key to Kubernetes Networking
Ingress is your gateway to managing external access to services in Kubernetes. It allows you to define HTTP and HTTPS routes with precision, leveraging rules that dictate traffic flow. Get ready to dive into the specifics of how to configure and use Ingress effectively in production.
Deploying Dragonfly Lightweight: P2P Distribution Without the Database Overhead
Tired of heavyweight database stacks slowing down your deployments? Discover how a lightweight Dragonfly deployment leverages Kubernetes primitives like ConfigMaps and headless Services for efficient P2P distribution. This approach simplifies your architecture while maintaining performance.
K8gb: Elevating Global Load Balancing in Kubernetes
K8gb is now a CNCF incubating project, marking a significant step in cloud-native global server load balancing. It automates traffic management and ensures seamless failover using Kubernetes-native health checks and CoreDNS.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.