Generate a Kubernetes Deployment Manifest with Best Practices
Create production-ready Kubernetes deployment manifests with security, autoscaling, networking, and reliability best practices built in.
๐ The Prompt
You are a Kubernetes platform engineer with deep expertise in production-grade deployments. Generate a complete set of Kubernetes manifests to deploy a [APPLICATION_TYPE] application to a [CLUSTER_ENVIRONMENT] cluster.
Application Details:
- Application name: [APP_NAME]
- Container image: [CONTAINER_IMAGE]:[TAG]
- Exposed port(s): [PORTS]
- Expected resource usage: [RESOURCE_PROFILE] (e.g., lightweight, moderate, high-compute)
- Number of replicas for production: [REPLICA_COUNT]
- Namespace: [NAMESPACE]
Generate the following Kubernetes manifests with production best practices:
1. **Namespace**: Create the namespace with appropriate labels and annotations.
2. **Deployment**: Include:
- Resource requests and limits appropriate for the [RESOURCE_PROFILE]
- Liveness, readiness, and startup probes with sensible defaults for a [APPLICATION_TYPE]
- Anti-affinity rules to spread pods across nodes
- Security context (non-root user, read-only root filesystem, drop all capabilities)
- Graceful shutdown with terminationGracePeriodSeconds
- Rolling update strategy with maxSurge and maxUnavailable
3. **Service**: Create a ClusterIP service exposing the application internally.
4. **Ingress / Gateway API**: Configure ingress with TLS termination for the domain [DOMAIN_NAME], using [INGRESS_CONTROLLER] (e.g., nginx, traefik, AWS ALB).
5. **ConfigMap & Secret**: Provide a ConfigMap for non-sensitive configuration values [CONFIG_VARS] and a Secret (with placeholder values) for sensitive data [SECRET_VARS].
6. **Horizontal Pod Autoscaler**: Configure HPA based on CPU and memory utilization with min/max replica bounds.
7. **PodDisruptionBudget**: Ensure minimum availability during node maintenance.
8. **NetworkPolicy**: Restrict ingress and egress traffic to only what is necessary.
Output each manifest as a separate YAML document (separated by ---) with inline comments explaining key decisions. Also provide a summary table listing each resource, its kind, and its purpose.
๐ก Tips for Better Results
Replace the resource profile placeholder with actual observed CPU/memory metrics from your application to get accurate resource requests and limits.
Specify your exact ingress controller so the annotations and API versions match your cluster's setup.
Review generated NetworkPolicy rules carefully โ overly restrictive policies can break service-to-service communication in your cluster.
๐ฏ Use Cases
Platform engineers and backend developers deploying containerized applications to Kubernetes who want a comprehensive, security-hardened starting point instead of writing manifests from scratch.