Skip to content

Deploy the API Using Kubernetes #16

@prasadhonrao

Description

@prasadhonrao

Description:
We need to deploy the DevCamper API to a Kubernetes cluster for improved scalability, management, and deployment automation. This will ensure that the API can run reliably across multiple environments with flexible scaling options.

Task:

  1. Create a Kubernetes Deployment for the API:

    • Write a deployment.yaml file for deploying the API.
    • Configure the deployment to:
      • Pull the API Docker image from a container registry (e.g., Docker Hub, GCR).
      • Set up the number of replicas (for scaling purposes).
      • Define environment variables using Kubernetes secrets and config maps.
      • Use liveness and readiness probes to ensure the application is running and ready to handle traffic.
    • Set up resource requests and limits (CPU, memory) for the API pods.
  2. Create a Kubernetes Service for the API:

    • Write a service.yaml file to expose the API internally within the cluster.
    • Configure the service type as ClusterIP (for internal access) or LoadBalancer (for external access, depending on the infrastructure).
    • Ensure that the service forwards traffic to the correct API pods.
  3. Set up Kubernetes Secrets and Config Maps:

    • Create a secrets.yaml file for securely storing sensitive information (e.g., JWT_SECRET, SMTP_PASSWORD).
    • Create a configmap.yaml file for storing non-sensitive configuration (e.g., API configuration, environment settings like NODE_ENV, PORT, etc.).
  4. Set up Ingress (Optional):

    • If required, configure an ingress.yaml file to expose the API externally, routing traffic based on domain names or paths.
    • Optionally configure SSL/TLS certificates using Kubernetes Ingress and Cert-Manager.
  5. Deploy MongoDB (Optional):

    • If MongoDB is not provided externally, create a Kubernetes deployment and service for MongoDB.
    • Use Persistent Volume Claims (PVC) to ensure data persistence for MongoDB across pod restarts.
  6. Create a Kubernetes Namespace:

    • Set up a dedicated namespace for the API (e.g., devcamper-api) to organize and manage resources more efficiently.
  7. Set Up Auto-Scaling (Optional):

    • Configure a Horizontal Pod Autoscaler (HPA) to scale the API based on CPU or memory utilization.
    • Define thresholds to automatically add or remove pods based on traffic load.
  8. Testing:

    • Test the deployment locally using a local Kubernetes cluster (e.g., Minikube or Docker Desktop).
    • Ensure that the API works as expected in the cluster environment.
    • Test the readiness and liveness probes, scaling, and failover mechanisms.
  9. Document Kubernetes Setup:

    • Update or create a section in README.md or SETUP.md to include instructions on:
      • Deploying the API to a Kubernetes cluster.
      • Managing secrets and config maps.
      • Testing and scaling the API in Kubernetes.

Acceptance Criteria:

  • A complete set of Kubernetes configuration files (deployment.yaml, service.yaml, secrets.yaml, configmap.yaml, and optionally ingress.yaml, hpa.yaml).
  • The API is successfully deployed to a Kubernetes cluster with multiple replicas, and exposed via a service or ingress.
  • Environment variables and secrets are securely managed using Kubernetes Secrets and ConfigMaps.
  • Documentation is provided for deploying and managing the API using Kubernetes.
  • The API is tested in the cluster environment, with proper scaling and reliability measures.

References:

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions