# EN: Marketing X Service - X (Twitter) social media integration and marketing
# VI: Marketing X Service - Tich hop mang xa hoi X (Twitter) va tiep thi
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mkt-x-service
  namespace: staging
  labels:
    app: mkt-x-service
    environment: staging
    platform: goodgo
    tier: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mkt-x-service
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: mkt-x-service
        environment: staging
    spec:
      containers:
      - name: mkt-x-service
        image: harbor.techbi.org/goodgo/mkt-x-service-net:staging
        ports:
        - containerPort: 8080
          protocol: TCP
        envFrom:
        - configMapRef:
            name: goodgo-config
        - secretRef:
            name: goodgo-secrets
        env:
        - name: ConnectionStrings__DefaultConnection
          valueFrom:
            secretKeyRef:
              name: goodgo-secrets
              key: MKT_X_DATABASE_URL
        - name: MktXService__ServiceName
          value: "mkt-x-service"
        - name: RabbitMQ__Host
          value: "rabbitmq"
        - name: RabbitMQ__Port
          value: "5672"
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health/live
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 3
        readinessProbe:
          httpGet:
            path: /health/ready
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 5
          timeoutSeconds: 3
          failureThreshold: 3
        startupProbe:
          httpGet:
            path: /health/live
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
          failureThreshold: 12
---
apiVersion: v1
kind: Service
metadata:
  name: mkt-x-service
  namespace: staging
  labels:
    app: mkt-x-service
    environment: staging
spec:
  selector:
    app: mkt-x-service
  ports:
  - name: http
    protocol: TCP
    port: 8080
    targetPort: 8080
  type: ClusterIP
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: mkt-x-service-hpa
  namespace: staging
  labels:
    app: mkt-x-service
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: mkt-x-service
  minReplicas: 1
  maxReplicas: 2
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 75
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80
