# ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
  name: common-config
  namespace: ${namespace}
data:
  ALLOWED_ORIGINS: ${allowed_origins}
  JPA_DDL_AUTO: update
  JPA_SHOW_SQL: 'true'
  # Actuator 설정
  MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE: '*'
  MANAGEMENT_ENDPOINT_HEALTH_SHOW_DETAILS: always
  MANAGEMENT_ENDPOINT_HEALTH_ENABLED: 'true'
  MANAGEMENT_ENDPOINTS_WEB_BASE_PATH: /actuator

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: member-config
  namespace: ${namespace}
data:
  SERVER_PORT: '8081'
  POSTGRES_HOST: ${postgres_host}
  POSTGRES_PORT: '5432'
  POSTGRES_DB: ${postgres_db_member}
  REDIS_HOST: ${redis_host}
  REDIS_PORT: '6380'
  JPA_DDL_AUTO: 'create-drop'
  JPA_SHOW_SQL: 'true'

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: store-config
  namespace: ${namespace}
data:
  SERVER_PORT: '8082'
  POSTGRES_HOST: ${postgres_host}
  POSTGRES_PORT: '5432'
  POSTGRES_DB: ${postgres_db_store}
  REDIS_HOST: ${redis_host}
  REDIS_PORT: '6380'
  JPA_DDL_AUTO: 'create-drop'
  JPA_SHOW_SQL: 'true'

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: marketing-content-config
  namespace: ${namespace}
data:
  SERVER_PORT: '8083'
  POSTGRES_HOST: ${postgres_host}
  POSTGRES_PORT: '5432'
  POSTGRES_DB: ${postgres_db_marketing_content}
  REDIS_HOST: ${redis_host}
  REDIS_PORT: '6380'
  JPA_DDL_AUTO: 'create-drop'
  JPA_SHOW_SQL: 'true'

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: ai-recommend-config
  namespace: ${namespace}
data:
  SERVER_PORT: '8084'
  POSTGRES_HOST: ${postgres_host}
  POSTGRES_PORT: '5432'
  POSTGRES_DB: ${postgres_db_ai_recommend}
  REDIS_HOST: ${redis_host}
  REDIS_PORT: '6380'
  JPA_DDL_AUTO: 'create-drop'
  JPA_SHOW_SQL: 'true'

---
# Secrets
apiVersion: v1
kind: Secret
metadata:
  name: common-secret
  namespace: ${namespace}
stringData:
  JWT_SECRET_KEY: ${jwt_secret_key}
type: Opaque

---
apiVersion: v1
kind: Secret
metadata:
  name: member-secret
  namespace: ${namespace}
stringData:
  JWT_ACCESS_TOKEN_VALIDITY: '3600000'
  JWT_REFRESH_TOKEN_VALIDITY: '86400000'
  POSTGRES_USER: ${postgres_user}
  POSTGRES_PASSWORD: ${postgres_password}
  REDIS_PASSWORD: ${redis_password}
type: Opaque

---
apiVersion: v1
kind: Secret
metadata:
  name: store-secret
  namespace: ${namespace}
stringData:
  POSTGRES_USER: ${postgres_user}
  POSTGRES_PASSWORD: ${postgres_password}
  REDIS_PASSWORD: ${redis_password}
type: Opaque

---
apiVersion: v1
kind: Secret
metadata:
  name: marketing-content-secret
  namespace: ${namespace}
stringData:
  POSTGRES_USER: ${postgres_user}
  POSTGRES_PASSWORD: ${postgres_password}
  REDIS_PASSWORD: ${redis_password}
type: Opaque

---
apiVersion: v1
kind: Secret
metadata:
  name: ai-recommend-secret
  namespace: ${namespace}
stringData:
  POSTGRES_USER: ${postgres_user}
  POSTGRES_PASSWORD: ${postgres_password}
  REDIS_PASSWORD: ${redis_password}
type: Opaque

---
# Deployments
apiVersion: apps/v1
kind: Deployment
metadata:
  name: member
  namespace: ${namespace}
  labels:
    app: member
spec:
  replicas: ${replicas}
  selector:
    matchLabels:
      app: member
  template:
    metadata:
      labels:
        app: member
    spec:
      imagePullSecrets:
      - name: acr-secret
      containers:
      - name: member
        image: ${member_image_path}
        imagePullPolicy: Always
        ports:
        - containerPort: 8081
        resources:
          requests:
            cpu: ${resources_requests_cpu}
            memory: ${resources_requests_memory}
          limits:
            cpu: ${resources_limits_cpu}
            memory: ${resources_limits_memory}
        envFrom:
        - configMapRef:
            name: common-config
        - configMapRef:
            name: member-config
        - secretRef:
            name: common-secret
        - secretRef:
            name: member-secret

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: store
  namespace: ${namespace}
  labels:
    app: store
spec:
  replicas: ${replicas}
  selector:
    matchLabels:
      app: store
  template:
    metadata:
      labels:
        app: store
    spec:
      imagePullSecrets:
      - name: acr-secret
      containers:
      - name: store
        image: ${store_image_path}
        imagePullPolicy: Always
        ports:
        - containerPort: 8082
        resources:
          requests:
            cpu: ${resources_requests_cpu}
            memory: ${resources_requests_memory}
          limits:
            cpu: ${resources_limits_cpu}
            memory: ${resources_limits_memory}
        envFrom:
        - configMapRef:
            name: common-config
        - configMapRef:
            name: store-config
        - secretRef:
            name: common-secret
        - secretRef:
            name: store-secret


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: marketing-content
  namespace: ${namespace}
  labels:
    app: marketing-content
spec:
  replicas: ${replicas}
  selector:
    matchLabels:
      app: marketing-content
  template:
    metadata:
      labels:
        app: marketing-content
    spec:
      imagePullSecrets:
      - name: acr-secret
      containers:
      - name: marketing-content
        image: ${marketing_content_image_path}
        imagePullPolicy: Always
        ports:
        - containerPort: 8083
        resources:
          requests:
            cpu: ${resources_requests_cpu}
            memory: ${resources_requests_memory}
          limits:
            cpu: ${resources_limits_cpu}
            memory: ${resources_limits_memory}
        envFrom:
        - configMapRef:
            name: common-config
        - configMapRef:
            name: marketing-content-config
        - secretRef:
            name: common-secret
        - secretRef:
            name: marketing-content-secret


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ai-recommend
  namespace: ${namespace}
  labels:
    app: ai-recommend
spec:
  replicas: ${replicas}
  selector:
    matchLabels:
      app: ai-recommend
  template:
    metadata:
      labels:
        app: ai-recommend
    spec:
      imagePullSecrets:
      - name: acr-secret
      containers:
      - name: ai-recommend
        image: ${ai_recommend_image_path}
        imagePullPolicy: Always
        ports:
        - containerPort: 8084
        resources:
          requests:
            cpu: ${resources_requests_cpu}
            memory: ${resources_requests_memory}
          limits:
            cpu: ${resources_limits_cpu}
            memory: ${resources_limits_memory}
        envFrom:
        - configMapRef:
            name: common-config
        - configMapRef:
            name: ai-recommend-config
        - secretRef:
            name: common-secret
        - secretRef:
            name: ai-recommend-secret


---
# Services
apiVersion: v1
kind: Service
metadata:
  name: member
  namespace: ${namespace}
spec:
  selector:
    app: member
  ports:
  - port: 80
    targetPort: 8081
  type: ClusterIP

---
apiVersion: v1
kind: Service
metadata:
  name: store
  namespace: ${namespace}
spec:
  selector:
    app: store
  ports:
  - port: 80
    targetPort: 8082
  type: ClusterIP

---
apiVersion: v1
kind: Service
metadata:
  name: marketing-content
  namespace: ${namespace}
spec:
  selector:
    app: marketing-content
  ports:
  - port: 80
    targetPort: 8083
  type: ClusterIP

---
apiVersion: v1
kind: Service
metadata:
  name: ai-recommend
  namespace: ${namespace}
spec:
  selector:
    app: ai-recommend
  ports:
  - port: 80
    targetPort: 8084
  type: ClusterIP

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: smarketing-ingress
  namespace: ${namespace}
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  ingressClassName: nginx
  rules:
    - host: smarketing.20.249.184.228.nip.io
      http:
        paths:
          - path: /api/auth
            pathType: Prefix
            backend:
              service:
                name: member
                port:
                  number: 80
          - path: /api/store
            pathType: Prefix
            backend:
              service:
                name: store
                port:
                  number: 80
          - path: /api/content
            pathType: Prefix
            backend:
              service:
                name: marketing-content
                port:
                  number: 80
          - path: /api/recommend
            pathType: Prefix
            backend:
              service:
                name: ai-recommend
                port:
                  number: 80

