Kubernetes Security for AI Workloads
Introduction
Kubernetes has become the de facto standard for deploying containerized applications, including AI models. However, running AI workloads in Kubernetes introduces specific security considerations.
Pod Security Standards
Enforcing Best Practices
Kubernetes provides Pod Security Standards to help ensure workloads follow security guidelines:
- Restricted - Most secure, recommended for production
- Baseline - Basic security, minimum requirements
- Privileged - No restrictions, for special use cases
Example policy enforcement:
apiVersion: v1
kind: Pod
metadata:
name: ai-inference
spec:
securityContext:
runAsNonRoot: true
fsGroup: 1000
containers:
- name: model-server
image: myregistry/my-model:latest
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
volumeMounts:
- mountPath: /tmp
name: tmp
readOnly: false
volumes:
- name: tmp
emptyDir: {}
Network Policies
AI services often need to communicate with external APIs or databases. Use network policies to control traffic:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-ai-service
spec:
podSelector:
matchLabels:
app: ai-service
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: frontend
ports:
- protocol: TCP
port: 8000
egress:
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
- 10.0.0.0/8
ports:
- protocol: TCP
port: 443
RBAC for AI Services
Implement fine-grained access control:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: model-reader
rules:
- apiGroups: [""]
resources: ["pods", "services"]
verbs: ["get", "list", "watch"]
- apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["get", "list"]
GPU Sharing and Security
When using NVIDIA GPUs in Kubernetes:
- Set
deviceRequestlimits - Prevent resource exhaustion - Use
nvidia.com/gpuresource - For proper scheduling - Enable GPU isolation - For multi-tenant environments
resources:
limits:
nvidia.com/gpu: 1
requests:
nvidia.com/gpu: 1
Secrets Management
Store model credentials securely:
apiVersion: v1
kind: Secret
metadata:
name: model-auth
type: Opaque
data:
api-key: c2VjcmV0LWtleSA=
Use SecretStore for external secret management (Vault, AWS Secrets Manager).
Monitoring Security Events
Set up monitoring for security-related events:
- Container runtime logs
- Node security events
- Network flow logs
- Pod lifecycle events
Example Prometheus query:
sum(rate(container_log_subtext{subtext=~"error|failed"}[5m]))
Conclusion
Kubernetes provides robust security primitives when properly configured. Key considerations for AI workloads include pod security policies, network isolation, GPU resource management, and secrets handling.
For more guidance on deploying AI infrastructure, our about page shares our philosophy on balancing innovation with stability.