apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{SERVICE_NAME}}-service
  namespace: bakery-ia
  labels:
    app.kubernetes.io/name: {{SERVICE_NAME}}-service
    app.kubernetes.io/component: microservice
    app.kubernetes.io/part-of: bakery-ia
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: {{SERVICE_NAME}}-service
      app.kubernetes.io/component: microservice
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{SERVICE_NAME}}-service
        app.kubernetes.io/component: microservice
    spec:
      containers:
      - name: {{SERVICE_NAME}}-service
        image: bakery/{{SERVICE_NAME}}-service:latest
        ports:
        - containerPort: 8000
          name: http
        env:
        - name: ENVIRONMENT
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: ENVIRONMENT
        - name: DEBUG
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: DEBUG
        - name: LOG_LEVEL
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: LOG_LEVEL
        - name: {{SERVICE_NAME_UPPER}}_DB_HOST
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: {{SERVICE_NAME_UPPER}}_DB_HOST
        - name: {{SERVICE_NAME_UPPER}}_DB_PORT
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: DB_PORT
        - name: {{SERVICE_NAME_UPPER}}_DB_NAME
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: {{SERVICE_NAME_UPPER}}_DB_NAME
        - name: {{SERVICE_NAME_UPPER}}_DB_USER
          valueFrom:
            secretKeyRef:
              name: database-secrets
              key: {{SERVICE_NAME_UPPER}}_DB_USER
        - name: {{SERVICE_NAME_UPPER}}_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: database-secrets
              key: {{SERVICE_NAME_UPPER}}_DB_PASSWORD
        - name: REDIS_HOST
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: REDIS_HOST
        - name: REDIS_PORT
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: REDIS_PORT
        - name: REDIS_PASSWORD
          valueFrom:
            secretKeyRef:
              name: redis-secrets
              key: REDIS_PASSWORD
        - name: RABBITMQ_HOST
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: RABBITMQ_HOST
        - name: RABBITMQ_PORT
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: RABBITMQ_PORT
        - name: RABBITMQ_USER
          valueFrom:
            secretKeyRef:
              name: rabbitmq-secrets
              key: RABBITMQ_USER
        - name: RABBITMQ_PASSWORD
          valueFrom:
            secretKeyRef:
              name: rabbitmq-secrets
              key: RABBITMQ_PASSWORD
        - name: AUTH_SERVICE_URL
          valueFrom:
            configMapKeyRef:
              name: bakery-config
              key: AUTH_SERVICE_URL
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health/live
            port: 8000
          initialDelaySeconds: 30
          timeoutSeconds: 5
          periodSeconds: 10
          failureThreshold: 3
        readinessProbe:
          httpGet:
            path: /health/ready
            port: 8000
          initialDelaySeconds: 15
          timeoutSeconds: 3
          periodSeconds: 5
          failureThreshold: 5

---
apiVersion: v1
kind: Service
metadata:
  name: {{SERVICE_NAME}}-service
  namespace: bakery-ia
  labels:
    app.kubernetes.io/name: {{SERVICE_NAME}}-service
    app.kubernetes.io/component: microservice
spec:
  type: ClusterIP
  ports:
  - port: 8000
    targetPort: 8000
    protocol: TCP
    name: http
  selector:
    app.kubernetes.io/name: {{SERVICE_NAME}}-service
    app.kubernetes.io/component: microservice