# storage-service.yaml
# Reference Kubernetes manifest for the Storage Service (Local Development Deployment)
# Replace placeholders with your environment-specific values before use.
#
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: storage-pvc  # Name of this PVC - referenced by the Deployment below
  namespace: storage-apis-dev  # Must match the namespace above
spec:
  accessModes:
    - ReadWriteOnce  # Single node access mode (suitable for MicroK8s hostpath)
                    # This means only one pod can mount this volume at a time
  resources:
    requests:
      storage: 10Gi  # Request 10GB of storage space
  storageClassName: microk8s-hostpath  # Use MicroK8s hostpath storage class

# Make sure to add this after the PVC, separated by ---
---

# Define the Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: storage-service  # Name of this deployment
  namespace: storage-apis-dev  # Must match the namespace above
  labels:
    app: storage-service  # Label for selection and organization
spec:
  replicas: 1  # Run 1 pod (single replica since we're using persistent storage)
  selector:
    matchLabels:
      app: storage-service
  template:
    metadata:
      labels:
        app: storage-service
    spec:
      containers:
      - name: storage  # Container name within the pod
        image: localhost:32000/storageapi_localfilesystem_service:local
        imagePullPolicy: Always  # Pull from the MicroK8s registry
        ports:
        - containerPort: 8011  # HTTP/REST API port (matches Docker setup)
          name: http
        - containerPort: 50051  # gRPC API port (matches Docker setup)
          name: grpc
        env:
        # Environment variables configure the storage service
        # These match the -e flags used in the Docker containerize step
        - name: FILESERVICE_STATIC_DIR
          value: "/data/storage"  # This matches the mountPath below where the PVC is mounted
        - name: FILESERVICE_SERVER_BASE_URI
          value: "file-storage://fileservice"
        - name: FILESERVICE_TEST_FOLDER_MODE
          value: "native"
        - name: GRPC_SERVER_PORT
          value: "50051"
        - name: HTTP_SERVER_PORT
          value: "8011"
        - name: REDIRECT_HOST
          value: "http://localhost"
        - name: REDIRECT_PORT
          value: "8011"
        volumeMounts:
        - name: storage-data
          mountPath: /data/storage  # This matches FILESERVICE_STATIC_DIR above
      volumes:
      - name: storage-data
        persistentVolumeClaim:
          claimName: storage-pvc  # Reference to the PVC created in Step 1

# Make sure to add this after the Deployment, separated by ---
---

# Define the Service
apiVersion: v1
kind: Service
metadata:
  name: storage-service  # Name of this service
  namespace: storage-apis-dev  # Must match the namespace above
  labels:
    app: storage-service  # Label for organization and selection
spec:
  selector:
    app: storage-service  # Routes traffic to pods with this label
                        # This must match the pod labels in the Deployment above
  ports:
  - name: http  # HTTP/REST API port name
    port: 8011  # Port that other services/clients will connect to
    targetPort: 8011  # Port on the pods that traffic will be forwarded to
    protocol: TCP
  - name: grpc
    port: 50051  # Port that other services/clients will connect to
    targetPort: 50051  # Port on the pods that traffic will be forwarded to
    protocol: TCP
  type: ClusterIP  # Only accessible within the cluster (internal)
  
  

