Prompt
ChatGPT, help me design a Kubernetes approach for dev staging and prod with consistent config, secrets, and RBAC
Latest observation
Here’s a practical Kubernetes approach for dev / staging / prod that keeps config, secrets, and RBAC consistent while still allowing each environment to differ safely.
1) Core design principles
Use these rules across all environments:
-
Same base manifests everywhere
- One application definition.
- Environment-specific overrides only for what truly differs.
-
Separate environments clearly
- Prefer separate namespaces at minimum.
- For stronger isolation, use separate clusters for prod vs non-prod.
-
No hardcoded config in app images
- Images should be immutable and environment-agnostic.
- Runtime config comes from ConfigMaps, Secrets, and environment overlays.
-
Least-privilege RBAC
- Separate human access from app/service account access.
- Use role-based permissions per namespace/environment.
-
GitOps if possible
- Store desired state in Git.
- Deploy with Argo CD or Flux for consistency and auditability.
2) Recommended environment layout
Option A: Separate namespaces in one cluster
Good for smaller teams or lower-risk workloads.
devstagingprod
Pros:
- Simpler, cheaper
- Easier to manage initially
Cons:
- Weaker blast-radius isolation
- Shared cluster issues can affect prod
Option B: Separate clusters for prod and non-prod
Recommended for most serious production setups.
- Cluster 1:
dev,staging - Cluster 2:
prod
Pros:
- Better isolation
- Safer upgrades and experiments
- Cleaner security boundaries
Cons:
- More operational overhead
Best practice: separate prod cluster if possible, namespaces within each cluster for logical separation.
3) Use a “base + overlays” config model
A strong pattern is:
- Base manifests define the app once.
- Environment overlays modify only environment-specific values.
Tools
- Kustomize: great for overlays and patching
- Helm: good if you want templating and packaging
- Plain YAML + overlays: possible, but less maintainable
Example structure
apps/
myapp/
base/
deployment.yaml
service.yaml
ingress.yaml
configmap.yaml
serviceaccount.yaml
rbac.yaml
kustomization.yaml
overlays/
dev/
kustomization.yaml
patch-deployment.yaml
patch-configmap.yaml
staging/
kustomization.yaml
patch-deployment.yaml
patch-configmap.yaml
prod/
kustomization.yaml
patch-deployment.yaml
patch-configmap.yaml
What belongs in base
- Deployment spec
- Service
- Ingress structure
- ServiceAccount
- Default resource limits/requests
- RBAC rules common to all envs
What belongs in overlays
- Replicas
- CPU/memory sizing
- Hostnames
- Feature flags
- Logging levels
- External endpoints
- Autoscaling thresholds
4) Config strategy: stable, explicit, and environment-driven
Use ConfigMaps for non-sensitive config
Examples:
- Feature flags
- Log level
- API base URLs
- Timeouts
- Non-secret service endpoints
Use environment variables carefully
Good for:
- Simple app settings
- Small numbers of values
Avoid overusing them for:
- Large structured config
- Anything needing hot reload
Better for complex config
Mount config files from ConfigMaps:
config.yamlapplication.propertiesnginx.conf
Example pattern
- Base config contains defaults
- Each environment overlay patches only differing values
Example:
apiVersion: v1
kind: ConfigMap
metadata:
name: myapp-config
data:
LOG_LEVEL: info
FEATURE_X_ENABLED: "false"
Dev overlay:
data:
LOG_LEVEL: debug
FEATURE_X_ENABLED: "true"
Prod overlay:
data:
LOG_LEVEL: warn
FEATURE_X_ENABLED: "false"
5) Secrets strategy: consistent and secure
Never commit raw secrets to Git.
Recommended options
A. External Secrets Operator
Store secrets in:
- AWS Secrets Manager
- Azure Key Vault
- GCP Secret Manager
- HashiCorp Vault
Kubernetes pulls them into Secrets automatically.
Best for:
- Strong security
- Central secret lifecycle management
- Rotation support
B. Sealed Secrets
Encrypt secrets before committing to Git.
Best for:
- GitOps-friendly workflows
- Teams not ready for external secret stores
C. SOPS + age or KMS
Encrypt secret files in Git and decrypt only in CI/CD or cluster.
Best for:
- Fine-grained Git-controlled secrets
- Strong auditability
Recommended secret principles
- One secret per app or per purpose
- Separate secrets by environment
- Different credentials for dev/staging/prod
- Rotate regularly
- Never reuse prod secrets in lower environments
Example secret flow
myapp-dev-dbmyapp-staging-dbmyapp-prod-db
6) RBAC model: separate humans, apps, and automation
Design RBAC around namespace boundaries and service accounts.
A. Human access
Create roles like:
- Developer
- QA
- SRE
- Read-only auditor
Example permissions
- Dev: full access in
devnamespace - QA: read/write in
staging - SRE: elevated access to all namespaces
- Auditor: read-only everywhere
B. App service accounts
Each app should use a dedicated ServiceAccount.
Example:
myapp-sa
Grant only what the app needs:
- Read its own config/secrets if required
- Access specific CRDs if necessary
- Avoid cluster-wide permissions unless truly needed
C. CI/CD automation
Use a dedicated service account for deployment tooling:
argocd-application-controller- or
ci-deployer
Scope it tightly:
- Namespace-specific deploy permissions
- Avoid cluster-admin
7) Example RBAC pattern
ServiceAccount
apiVersion: v1
kind: ServiceAccount
metadata:
name: myapp-sa
namespace: dev
Role
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: myapp-read-config
namespace: dev
rules:
- apiGroups: [""]
resources: ["configmaps", "secrets"]
resourceNames: ["myapp-config", "myapp-secret"]
verbs: ["get", "list", "watch"]
RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: myapp-read-config-binding
namespace: dev
subjects:
- kind: ServiceAccount
name: myapp-sa
namespace: dev
roleRef:
kind: Role
name: myapp-read-config
apiGroup: rbac.authorization.k8s.io
Note: If the app only needs mounted secrets at startup, it may not need API permissions at all.
8) Keep policies consistent with templates and guardrails
To reduce drift, standardize:
- Resource requests/limits
- Labels and annotations
- Pod security standards
- Network policies
- Liveness/readiness probes
- Image pull policy
- Security context
Add policy enforcement
Use:
- Kyverno or OPA Gatekeeper
- Enforce:
- no privileged pods
- no latest tags
- resource limits required
- approved registries only
- mandatory labels
9) Environment-specific differences to allow
These should usually vary by environment:
- Replica count
- Resource requests/limits
- HPA thresholds
- Log verbosity
- External service endpoints
- Feature flags
- Ingress hostnames
- TLS certificate references
- Database instance/credentials
- Cache size/timeouts
These should stay consistent:
- Container image build process
- App deployment pattern
- Labels/annotations standards
- ServiceAccount naming convention
- RBAC model
- Observability stack integration
- Health checks structure
10) Suggested Git repository structure
repo/
apps/
myapp/
base/
overlays/
dev/
staging/
prod/
infra/
namespaces/
rbac/
policies/
external-secrets/
ingress/
clusters/
dev/
staging/
prod/
Or if using GitOps by environment:
gitops/
dev/
staging/
prod/
Each environment folder points to the same base app config with overlays.
11) Example deployment flow
- Developer commits app code.
- CI builds immutable image tagged with git SHA.
- CI updates deployment manifest or image tag in Git.
- GitOps controller syncs to dev.
- After verification, promote same image to staging.
- After approval, promote same image to prod.
Key rule
Use the same image artifact across all environments. Only config changes between them.
12) Promotion model
A good promotion sequence:
- Dev
- fast feedback
- debugging enabled
- permissive scaling
- Staging
- production-like config
- same secrets pattern as prod, but separate values
- validation and load tests
- Prod
- hardened config
- strict RBAC
- least privilege
- tighter alerts and policies
13) Practical security checklist
- Separate namespaces for dev/staging/prod
- Separate prod cluster if feasible
- No shared secrets across environments
- ConfigMaps for non-sensitive config
- External Secrets or Sealed Secrets for secrets
- ServiceAccounts per app
- RBAC limited to namespace scope
- NetworkPolicies enabled
- Pod Security Standards enforced
- Admission policies for image and security restrictions
- GitOps with audit trail
- Resource requests/limits defined
14) A good default recommendation
If you want a solid, modern baseline:
- Kustomize overlays for config consistency
- External Secrets Operator for secrets
- Argo CD for GitOps deployment
- Namespaces for dev/staging/prod
- Separate cluster for prod if possible
- RBAC per namespace and per app service account
- Kyverno/Gatekeeper for policy enforcement
15) If you want a simple template to start with
Use this architecture:
base/contains one app specoverlays/dev,overlays/staging,overlays/prodConfigMapfor non-secret configExternalSecretfor secret referencesServiceAccount+Role+RoleBindingfor app access- Argo CD syncs each overlay to its namespace
If you want, I can also provide:
- a full sample repository layout,
- a Kustomize example for dev/staging/prod,
- or a complete RBAC + ExternalSecrets YAML template.