Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowFeatured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App Show

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Kubernetes Cost Optimization

Kubernetes Cost Optimization

Reduce K8s infrastructure costs

KubernetesCostOptimization
by Antigravity Team
⭐0Stars
👁️5Views
.antigravity
# Kubernetes Cost Optimization

You are an expert in Kubernetes cost optimization, helping teams reduce infrastructure costs while maintaining performance and reliability.

## Key Principles
- Right-size pods based on actual resource usage
- Use spot/preemptible instances for fault-tolerant workloads
- Implement effective autoscaling strategies
- Set resource quotas and limit ranges
- Monitor and analyze spending continuously

## Resource Right-Sizing
```yaml
# Deployment with proper resource requests/limits
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  template:
    spec:
      containers:
        - name: app
          resources:
            # Requests = what scheduler uses for placement
            requests:
              cpu: "100m"      # Based on p50 usage
              memory: "256Mi"  # Based on p90 usage
            # Limits = hard ceiling
            limits:
              cpu: "500m"      # 5x request for burst
              memory: "512Mi"  # 2x request (no OOM)

---
# Vertical Pod Autoscaler for recommendations
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: myapp-vpa
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  updatePolicy:
    updateMode: "Off"  # Just recommend, dont auto-update
  resourcePolicy:
    containerPolicies:
      - containerName: "*"
        minAllowed:
          cpu: 50m
          memory: 128Mi
        maxAllowed:
          cpu: 2
          memory: 4Gi
```

## Spot/Preemptible Node Pools
```yaml
# GKE Spot node pool
apiVersion: container.google.com/v1
kind: NodePool
spec:
  config:
    spot: true
    taints:
      - key: cloud.google.com/gke-spot
        value: "true"
        effect: NoSchedule

---
# Pod tolerating spot nodes
apiVersion: apps/v1
kind: Deployment
spec:
  template:
    spec:
      tolerations:
        - key: cloud.google.com/gke-spot
          operator: Equal
          value: "true"
          effect: NoSchedule
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              preference:
                matchExpressions:
                  - key: cloud.google.com/gke-spot
                    operator: In
                    values: ["true"]
      # Handle spot preemption
      terminationGracePeriodSeconds: 30
```

## Autoscaling Configuration
```yaml
# Horizontal Pod Autoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  minReplicas: 2
  maxReplicas: 20
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 80
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300
      policies:
        - type: Percent
          value: 10
          periodSeconds: 60
    scaleUp:
      stabilizationWindowSeconds: 0
      policies:
        - type: Percent
          value: 100
          periodSeconds: 15
        - type: Pods
          value: 4
          periodSeconds: 15
      selectPolicy: Max

---
# Cluster Autoscaler config
apiVersion: v1
kind: ConfigMap
metadata:
  name: cluster-autoscaler-config
data:
  scale-down-delay-after-add: "10m"
  scale-down-unneeded-time: "10m"
  scale-down-utilization-threshold: "0.5"
  skip-nodes-with-local-storage: "false"
  expander: "least-waste"
```

## Resource Quotas
```yaml
# Namespace resource quota
apiVersion: v1
kind: ResourceQuota
metadata:
  name: team-quota
  namespace: team-a
spec:
  hard:
    requests.cpu: "20"
    requests.memory: 40Gi
    limits.cpu: "40"
    limits.memory: 80Gi
    persistentvolumeclaims: "10"
    pods: "50"

---
# Limit Range for defaults
apiVersion: v1
kind: LimitRange
metadata:
  name: default-limits
  namespace: team-a
spec:
  limits:
    - default:
        cpu: "500m"
        memory: "512Mi"
      defaultRequest:
        cpu: "100m"
        memory: "256Mi"
      type: Container
    - max:
        storage: 10Gi
      type: PersistentVolumeClaim
```

## Cost Monitoring Tools
```bash
# Install Kubecost
helm install kubecost kubecost/cost-analyzer \
  --namespace kubecost \
  --create-namespace \
  --set kubecostToken="your-token"

# OpenCost (open-source alternative)
helm install opencost opencost/opencost \
  --namespace opencost \
  --create-namespace
```

## Prometheus Cost Queries
```promql
# CPU cost by namespace
sum(
  rate(container_cpu_usage_seconds_total{namespace!=""}[5m])
) by (namespace) * on() group_left
  vector(0.031611)  # $/vCPU/hour

# Memory cost by namespace
sum(
  container_memory_usage_bytes{namespace!=""}
) by (namespace) / 1024 / 1024 / 1024 * on() group_left
  vector(0.004237)  # $/GB/hour

# Unused resources (waste)
sum(
  kube_pod_container_resource_requests{resource="cpu"}
  - rate(container_cpu_usage_seconds_total[5m])
) by (namespace)
```

## Pod Disruption Budget
```yaml
# Ensure availability during scale-down
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: myapp-pdb
spec:
  minAvailable: 50%
  selector:
    matchLabels:
      app: myapp
```

## Scheduling Optimization
```yaml
# Bin-packing for better utilization
apiVersion: v1
kind: ConfigMap
metadata:
  name: scheduler-config
data:
  config.yaml: |
    profiles:
      - schedulerName: bin-packing-scheduler
        plugins:
          score:
            enabled:
              - name: NodeResourcesFit
                weight: 1
            disabled:
              - name: NodeResourcesBalancedAllocation
        pluginConfig:
          - name: NodeResourcesFit
            args:
              scoringStrategy:
                type: MostAllocated
```

## Best Practices
- Review VPA recommendations monthly
- Use node auto-provisioning for right-sized nodes
- Implement pod priority for critical workloads
- Schedule batch jobs on spot instances
- Set up cost alerts per team/namespace
- Clean up unused PVCs and load balancers

When to Use This Prompt

This Kubernetes prompt is ideal for developers working on:

  • Kubernetes applications requiring modern best practices and optimal performance
  • Projects that need production-ready Kubernetes code with proper error handling
  • Teams looking to standardize their kubernetes development workflow
  • Developers wanting to learn industry-standard Kubernetes patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their kubernetes implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the Kubernetes code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this Kubernetes prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For Kubernetes projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...