apiVersion: apps/v1
kind: Deployment
metadata:
  name: search-rpc
  namespace: juwan
  labels:
    app: search-rpc
spec:
  replicas: 1
  selector:
    matchLabels:
      app: search-rpc
  template:
    metadata:
      labels:
        app: search-rpc
    spec:
      imagePullSecrets:
        - name: registry-creds
      containers:
      - name: search-rpc
        image: registry.juwan.xhttp.zip/juwan/search-rpc:latest
        ports:
        - name: grpc
          containerPort: 8080
        - name: metrics
          containerPort: 4001
        env:
          - name: PD_USERNAME
            valueFrom:
              secretKeyRef:
                name: search-db-app
                key: username
          - name: DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: search-db-app
                key: password
          - name: DB_NAME
            valueFrom:
              secretKeyRef:
                name: search-db-app
                key: dbname
          - name: DB_HOST
            value: search-db-rw.juwan
          - name: DB_HOST_RO
            value: search-db-ro.juwan
          - name: DB_PORT
            value: "5432"
          - name: REDIS_HOST
            value: search-redis-master.juwan
          - name: REDIS_PORT
            value: "6379"
          - name: REDIS_PASSWORD
            valueFrom:
              secretKeyRef:
                name: search-redis
                key: password
          - name: SNOWFLAKE_RPC_TARGET
            value: "snowflake-svc.juwan:8080"
        resources:
          requests:
            cpu: 10m
            memory: 32Mi
          limits:
            memory: 512Mi

---
apiVersion: v1
kind: Service
metadata:
  name: search-rpc-svc
  namespace: juwan
spec:
  ports:
    - name: grpc
      port: 8080
      targetPort: 8080
    - name: metrics
      port: 4001
      targetPort: 4001
  selector:
    app: search-rpc

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: search-api
  namespace: juwan
  labels:
    app: search-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: search-api
  template:
    metadata:
      labels:
        app: search-api
    spec:
      imagePullSecrets:
        - name: registry-creds
      containers:
      - name: search-api
        image: registry.juwan.xhttp.zip/juwan/search-api:latest
        ports:
        - name: http
          containerPort: 8888
        - name: metrics
          containerPort: 4001
        env:
          - name: SEARCH_RPC_TARGET
            value: "search-rpc-svc.juwan:8080"
        resources:
          requests:
            cpu: 10m
            memory: 32Mi
          limits:
            memory: 512Mi

---
apiVersion: v1
kind: Service
metadata:
  name: search-api-svc
  namespace: juwan
spec:
  ports:
    - name: http
      port: 8888
      targetPort: 8888
    - name: metrics
      port: 4001
      targetPort: 4001
  selector:
    app: search-api
