Course contentsShow
← Cloud and Infrastructure
Lesson 2275 of 2,98948. Secrets ManagementFree lesson

Vault Agent Injector for Kubernetes

Learn how Vault Agent Injector automatically injects secrets into pods using sidecar containers and init containers.

Vault Agent Injector for Kubernetes

What you'll learn: How to automatically inject secrets from HashiCorp Vault into Kubernetes pods without modifying application code.

The Problem It Solves

After learning about Kubernetes Secrets limitations and the External Secrets Operator pattern, you need a seamless way to bridge Vault with your pods. Manually configuring Vault authentication and secret retrieval in every application is error-prone and tedious.

How Vault Agent Injector Works

The Vault Agent Injector is a Kubernetes mutating admission webhook controller that intercepts pod creation requests and automatically injects sidecar containers and init containers into your pods based on annotations.

Think of it like a valet service: instead of each application parking its own car (fetching secrets), you hand your keys (pod annotations) to the valet (injector), and it handles everything—starting the engine (init container authenticating to Vault), keeping it running (sidecar refreshing tokens), and delivering your luggage (secrets) right to your room (application container).

The Two Container Pattern

When you annotate a pod, the injector adds:

  1. Init container: Runs before your app starts, authenticates to Vault using Kubernetes service account tokens, retrieves secrets, and writes them to a shared volume
  2. Sidecar container: Continues running alongside your app, automatically renewing Vault tokens and refreshing secrets when they change

Your application simply reads secrets from a mounted file path like /vault/secrets/config.txt—no Vault client library or authentication logic needed in your code.

Simple Annotation Example

annotations:
  vault.hashicorp.com/agent-inject: "true"
  vault.hashicorp.com/role: "myapp"
  vault.hashicorp.com/agent-inject-secret-config.txt: "secret/data/myapp"

These annotations tell the injector to fetch secret/data/myapp from Vault and write it to /vault/secrets/config.txt in your pod.

Key Takeaway: Vault Agent Injector automates secret delivery using init and sidecar containers, letting applications consume secrets as files without embedding Vault logic or credentials.