---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: comments-svc
  namespace: dev
  labels:
    app: comments-svc
spec:
  replicas: 3
  selector:
    matchLabels:
      app: comments-svc
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 25%
  template:
    metadata:
      labels:
        app: comments-svc
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: node-pool
                  operator: In
                  values:
                    - internal
      containers:
        - name: comments-svc
          image: "comments-svc:latest"
          imagePullPolicy: Always
          resources:
            requests:
              cpu: 100m
              memory: 200Mi
            limits:
              cpu: 300m
              memory: 300Mi
          envFrom:
            - configMapRef:
                name: comments-svc
            - secretRef:
                name: database
            - secretRef:
                name: cache
          ports:
            - name: http
              containerPort: 50051
              protocol: TCP
          livenessProbe:
            exec:
              command:
                - "/bin/grpc_health_probe"
                - "-addr=:50051"
            initialDelaySeconds: 10
            periodSeconds: 30
            successThreshold: 1
            failureThreshold: 3
            timeoutSeconds: 10
          readinessProbe:
            exec:
              command:
                - "/bin/grpc_health_probe"
                - "-addr=:50051"
            initialDelaySeconds: 5
            periodSeconds: 30
            successThreshold: 1
            failureThreshold: 3
            timeoutSeconds: 10
# ---
# apiVersion: autoscaling/v2beta1
# kind: HorizontalPodAutoscaler
# metadata:
#   name: comments-svc
#   namespace: dev
#   labels:
#     app: comments-svc
# spec:
#   scaleTargetRef:
#     apiVersion: apps/v1
#     name: comments-svc
#     kind: Deployment
#   minReplicas: 3
#   maxReplicas: 10
#   metrics:
#     - type: Resource
#       resource:
#         name: cpu
#         targetAverageUtilization: 60
#     - type: Resource
#       resource:
#         name: memory
#         targetAverageUtilization: 85
