apiVersion: v1
kind: Namespace
metadata:
  name: scaling-test
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: scaling-workload
  namespace: scaling-test
spec:
  replicas: 0
  selector:
    matchLabels:
      app: scaling-workload
  template:
    metadata:
      labels:
        app: scaling-workload
    spec:
      tolerations:
      - key: "karpenter.sh/unregistered"
        operator: "Equal"
        value: "true"
        effect: "NoSchedule"
      containers:
      - name: app
        image: nginx:latest
        resources:
          requests:
            cpu: 1
            memory: 1Gi
          limits:
            cpu: 1
            memory: 1Gi
---
apiVersion: v1
kind: Service
metadata:
  name: scaling-workload
  namespace: scaling-test
spec:
  selector:
    app: scaling-workload
  ports:
  - port: 80
    targetPort: 80
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: scaling-workload-hpa
  namespace: scaling-test
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: scaling-workload
  minReplicas: 1
  maxReplicas: 20
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 70