Successfully created a complete Kubernetes operator called vault-sync-operator that automatically syncs Kubernetes secrets to HashiCorp Vault using annotations on Deployments and Secrets.
vault-sync-operator/
├── cmd/
│ └── main.go # Main application entry point
├── internal/
│ ├── controller/
│ │ ├── deployment_controller.go # Deployment reconciler logic
│ │ ├── secret_controller.go # Secret reconciler logic
│ │ └── sync_common.go # Shared sync functionality
│ ├── vault/
│ │ ├── client.go # Vault client with K8s auth
│ │ └── health.go # Vault health checks
│ ├── goruntime/
│ │ ├── config.go # Go runtime optimization
│ │ └── config_test.go # Runtime configuration tests
│ └── metrics/
│ └── metrics.go # Prometheus metrics
├── config/
│ ├── default/ # Kustomize default configuration
│ ├── manager/ # Manager deployment configuration
│ ├── rbac/ # RBAC permissions
├── docs/ # Documentation
│ ├── README.md # Documentation index
│ ├── PROJECT_SUMMARY.md # Complete project summary
│ ├── DEPLOYMENT.md # Deployment guide
│ ├── VAULT-SETUP-GUIDE.md # Vault configuration guide
│ ├── VAULT-AUTH-TROUBLESHOOTING.md # Auth troubleshooting
│ ├── VAULT-ADDRESS-CONFIGURATION.md # Address configuration
│ ├── VM-DEPLOYMENT-README.md # VM deployment guide
│ ├── multi-cluster-deployment.md # Multi-cluster guide
│ ├── performance-optimizations.md # Performance guide
│ ├── secret-rotation-detection.md # Secret rotation
│ └── ci-cd-pipeline.md # CI/CD documentation
├── examples/ # Example deployment files
├── scripts/
│ ├── setup-vault.sh # Vault configuration script
│ ├── dev.sh # Development environment setup
│ ├── deploy-on-vm.sh # VM deployment script
│ ├── build-vm-manifests.sh # VM manifest builder
│ ├── validate-and-package.sh # Manifest validation
│ └── validate-manifests.sh # Manifest syntax validation
├── test/ # Test files
│ └── suite_test.go # Test suite setup
├── hack/
│ └── boilerplate.go.txt # License header template
├── charts/ # Helm chart
│ └── vault-sync-operator/ # Operator Helm chart
├── deploy/
│ └── manual/ # Manual deployment manifests
├── Dockerfile # Container image build
├── Makefile # Build and deployment targets
├── go.mod # Go module dependencies
└── README.md # Main documentation
internal/vault/client.go)internal/controller/deployment_controller.go)cmd/main.go)| Annotation | Required | Description | Example |
|---|---|---|---|
vault-sync.io/path |
Yes | Vault storage path (enables sync) | "secret/data/my-app" |
vault-sync.io/secrets |
No | Custom secret configuration JSON | See examples |
Note: The presence of vault-sync.io/path automatically enables vault sync on both Deployments and Secrets. The vault-sync.io/secrets annotation is optional and only needed for selective key syncing or prefixing.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
annotations:
vault-sync.io/path: "secret/data/my-app"
# Optional: vault-sync.io/secrets for custom configuration
spec:
# ... deployment spec
apiVersion: v1
kind: Secret
metadata:
name: my-secret
annotations:
vault-sync.io/path: "secret/data/my-secret"
# Optional: vault-sync.io/secrets for custom configuration
type: Opaque
data:
key1: dmFsdWUx # base64 encoded value
The operator supports multiple deployment methods:
See the Deployment Guide for detailed installation instructions.
The operator supports various configuration flags:
--vault-addr: Vault server address--vault-role: Kubernetes auth role name--vault-auth-path: Vault auth path--metrics-bind-address: Metrics endpoint address--health-probe-bind-address: Health probe address--leader-elect: Enable leader electionThe operator is production-ready for deployment in Kubernetes environments with HashiCorp Vault integration.
/healthz): Validates Vault server connectivity/readyz): Ensures Vault authentication is workingThe operator exposes comprehensive metrics on port :8080:
vault_sync_operator_sync_attempts_total: Sync attempt counters with success/failure labelsvault_sync_operator_sync_duration_seconds: Operation duration histogramsvault_sync_operator_secrets_discovered: Number of auto-discovered secretsvault_sync_operator_secret_not_found_errors_total: Missing Kubernetes secretsvault_sync_operator_secret_key_missing_errors_total: Missing keys within secretsvault_sync_operator_config_parse_errors_total: Configuration parsing failuresvault_sync_operator_vault_write_errors_total: Vault write errors by typevault_sync_operator_auth_attempts_total: Vault authentication success/failure ratesComprehensive error detection and reporting for:
All errors are logged with structured context and tracked via Prometheus metrics for monitoring and alerting
The operator is optimized for Kubernetes environments with automatic Go runtime configuration:
go.uber.org/automaxprocs to respect container CPU limitsvault_sync_operator_runtime_info: Tracks GOMAXPROCS, GOMEMLIMIT, and GC configurationvault-sync.io/preserve-on-delete: "true" prevents Vault secret deletion when deployments are deleted