apiVersion: apps/v1
kind: Deployment
metadata:
  name: legal-documents-service
  namespace: the-order
  labels:
    app: legal-documents-service
    version: v1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: legal-documents-service
  template:
    metadata:
      labels:
        app: legal-documents-service
        version: v1
    spec:
      containers:
      - name: legal-documents
        image: theorder/legal-documents-service:latest
        ports:
        - containerPort: 4005
          name: http
        env:
        - name: PORT
          value: "4005"
        - name: NODE_ENV
          value: "production"
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: legal-documents-secrets
              key: database-url
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 4005
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: 4005
          initialDelaySeconds: 10
          periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: legal-documents-service
  namespace: the-order
spec:
  selector:
    app: legal-documents-service
  ports:
  - port: 80
    targetPort: 4005
    protocol: TCP
  type: ClusterIP
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: legal-documents-service-hpa
  namespace: the-order
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: legal-documents-service
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80

