
# Cursor生成的Terraform模块示例
module "eks_cluster" {
source = "terraform-aws-modules/eks/aws"
version = "~> 19.0"
cluster_name = "prod-eks"
cluster_version = "1.28"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
# AI优化的节点组配置
eks_managed_node_groups = {
general = {
desired_size = 3
min_size = 1
max_size = 10
instance_types = ["t3.medium"]
capacity_type = "SPOT"
}
}
}下面是由 Cursor 智能生成的一个完整应用部署配置示例,它一次性输出了 Deployment(含资源限制与健康检查)、Service 和 Ingress 三个资源,你只需根据实际项目微调镜像名称和域名即可:
# Cursor 生成的完整 Kubernetes 应用部署配置
# 包含 Deployment(资源限制、健康检查)、Service 和 Ingress
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-deployment
labels:
app: my-app
spec:
replicas: 3 # 副本数
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:latest
ports:
- containerPort: 8080 # 应用端口
# 资源限制与请求,避免资源争抢
resources:
requests:
memory: "256Mi" # 最低请求内存
cpu: "500m" # 最低请求 CPU(0.5 核)
limits:
memory: "512Mi" # 最大内存限制
cpu: "1" # 最大 CPU(1 核)
# 存活探针:检测容器是否正常运行
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30 # 容器启动后等待 30 秒开始探测
periodSeconds: 10 # 每 10 秒探测一次
failureThreshold: 3 # 连续失败 3 次后重启容器
# 就绪探针:检测容器是否准备好接收流量
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5 # 启动后等待 5 秒
periodSeconds: 5 # 每 5 秒探测一次
failureThreshold: 2 # 连续失败 2 次后标记为未就绪
# 启动探针(可选):用于慢启动应用,避免与存活探针冲突
startupProbe:
httpGet:
path: /startup
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
failureThreshold: 30 # 最长等待 30*10=300 秒
---
# Service 暴露应用
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app # 关联上面的 Deployment
ports:
- protocol: TCP
port: 80 # Service 对外端口
targetPort: 8080 # 转发到容器端口
type: ClusterIP
---
# Ingress 配置外部访问路由
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx # 使用 nginx ingress 控制器
rules:
- host: myapp.example.com # 域名
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app-service # 路由到上面的 Service
port:
number: 80# Cursor生成的GitHub Actions工作流
name: GitOps Deployment Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Validate Kubernetes Manifests
run: |
kubectl apply --dry-run=server -f k8s/
- name: Validate Terraform
run: |
cd terraform && terraform init && terraform validate
deploy:
needs: validate
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy to Kubernetes
uses: argo-cd/actions/argocd-deploy@v1
with:
argocd-url: ${{ secrets.ARGOCD_SERVER }}
argocd-token: ${{ secrets.ARGOCD_TOKEN }}
app-name: my-app
revision: ${{ github.sha }}