Kubernetes Setup Best Practices¶
Overview¶
This guide provides best practices for setting up Kubernetes environments for secure container scanning. Following these practices ensures that your scanning infrastructure is secure, reliable, and follows the principle of least privilege.
Security-First Practices¶
Namespace Isolation¶
Always use dedicated namespaces for scanning operations:
Benefits:
- Isolates scanner resources from other workloads
- Allows namespace-specific RBAC controls
- Simplifies resource management and cleanup
Least Privilege RBAC¶
Create role-based access controls that provide only the minimum necessary permissions:
Benefits:
- Minimizes potential damage from compromised credentials
- Follows security principle of least privilege
- Creates clear audit trails for scanner actions
Ephemeral Credentials¶
Use short-lived credentials for scanning operations:
Benefits:
- Reduces risk window if credentials are compromised
- Enforces regular credential rotation
- Simplifies credential management
Network Policies¶
Implement network policies to restrict scanner pod communications:
Benefits:
- Prevents lateral movement in case of compromise
- Enforces explicit communication paths
- Reduces attack surface
Operational Best Practices¶
Resource Limits¶
Always set resource limits for scanner components:
Benefits:
- Prevents resource exhaustion attacks
- Ensures predictable cluster resource utilization
- Improves scheduler decision making
Liveness and Readiness Probes¶
Implement appropriate health checks for longer-running scanner components:
Benefits:
- Improves reliability and automatic recovery
- Prevents traffic to non-ready instances
- Simplifies troubleshooting
Logging and Monitoring¶
Configure comprehensive logging for scanner operations:
Benefits:
- Creates audit trail for compliance requirements
- Aids in troubleshooting and debugging
- Enables operational insights
Cluster Configuration Best Practices¶
API Server Throttling¶
Configure appropriate API server throttling to handle scanner requests:
Benefits:
- Prevents API server overload
- Ensures cluster stability during scanning
- Maintains responsiveness for critical operations
Admission Controllers¶
Use admission controllers to enforce security policies:
Benefits:
- Enforces consistent security policies
- Prevents privileged scanner pods by default
- Maintains cluster security posture
Feature Gates¶
Enable only necessary feature gates for scanning:
Benefits:
- Reduces potential attack surface
- Simplifies security analysis
- Improves stability
Environment-Specific Recommendations¶
Development and Testing¶
For development and testing environments:
- Use Minikube with our provided setup script
- Enable debug logs for scanner components
- Consider using local filesystem for profiles and results
CI/CD Environments¶
For CI/CD pipeline integration:
- Use dedicated service accounts per pipeline
- Configure short-lived tokens (e.g., 15 minutes)
- Store sensitive configuration in CI/CD secrets
Production Environments¶
For production environments:
- Implement strict network policies
- Use node affinity to run scanners on designated nodes
- Configure comprehensive audit logging
- Consider using Pod Security Standards
High Availability Considerations¶
For production use, consider:
- Multiple Scanner Deployments: Deploy scanners across multiple namespaces or clusters
- Load Balancing: Distribute scanning workloads evenly
- Failure Domains: Ensure scanners span multiple availability zones
- Graceful Degradation: Design for partial functionality during outages
Validation and Compliance¶
Regularly validate your scanner setup:
Next Steps¶
After implementing these best practices:
- Configure secure kubeconfig files
- Set up label-based RBAC for fine-grained control
- Implement security-focused scanning thresholds