|
| 1 | + |
| 2 | +# Sparrow API Helm Chart |
| 3 | + |
| 4 | +This repository contains the Helm chart for deploying the `sparrow-api` application. The chart allows for easy deployment, scaling, and configuration of the API on Kubernetes clusters. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | + |
| 8 | +Before installing the `sparrow-api` Helm chart, make sure the following dependencies are set up: |
| 9 | + |
| 10 | +1. **MongoDB**: Install MongoDB using Helm. |
| 11 | + ```bash |
| 12 | + helm repo add bitnami https://charts.bitnami.com/bitnami |
| 13 | + helm install sparrow-mongodb bitnami/mongodb --namespace sparrow-dev |
| 14 | + ``` |
| 15 | + |
| 16 | +2. **Kafka**: Install Kafka using Helm. |
| 17 | + ```bash |
| 18 | + helm repo add bitnami https://charts.bitnami.com/bitnami |
| 19 | + helm install sparrow-kafka bitnami/kafka --namespace sparrow-dev |
| 20 | + ``` |
| 21 | + |
| 22 | +Ensure that MongoDB and Kafka services are running and retrieve the connection URLs for each service, as they are required to configure the `sparrow-api` chart. |
| 23 | + |
| 24 | +## Installing the Chart |
| 25 | + |
| 26 | +1. **Add the Sparrow Helm Repository** (if hosted externally): |
| 27 | + ```bash |
| 28 | + helm repo add sparrow-api https://helm-chart-url |
| 29 | + helm repo update |
| 30 | + ``` |
| 31 | + |
| 32 | +2. **Install the Chart**: |
| 33 | + Replace `<namespace>` with your desired namespace (e.g., `sparrow-dev`). |
| 34 | + |
| 35 | + ```bash |
| 36 | + helm install sparrow-api sparrow-api/sparrow-api --namespace <namespace> |
| 37 | + ``` |
| 38 | + |
| 39 | +### Configuring MongoDB and Kafka URLs |
| 40 | + |
| 41 | +To configure the chart to connect to MongoDB and Kafka, pass in their URLs using `--set` or update the `values.yaml` file. |
| 42 | + |
| 43 | +#### Example with `--set` |
| 44 | +```bash |
| 45 | +helm install sparrow-api sparrow-api/sparrow-api --namespace sparrow-dev --set secrets.DB_URL="mongodb://<username>:<password>@mongodb-service/" --set secrets.KAFKA_BROKER="<KAFKA_URL>:9092" |
| 46 | +``` |
| 47 | + |
| 48 | +### Configuration |
| 49 | + |
| 50 | +The following table lists common configurable parameters of the `sparrow-api` chart and their default values in `values.yaml`: |
| 51 | + |
| 52 | +| Parameter | Description | Default | |
| 53 | +|---------------------------------------|------------------------------------------------------|-----------------------------| |
| 54 | +| `replicaCount` | Number of replicas for the API | `1` | |
| 55 | +| `autoscaling.enabled` | Enable horizontal pod autoscaling | `true` | |
| 56 | +| `autoscaling.minReplicas` | Minimum number of replicas | `1` | |
| 57 | +| `autoscaling.maxReplicas` | Maximum number of replicas | `10` | |
| 58 | +| `autoscaling.targetCPUUtilizationPercentage` | Target CPU usage percentage for scaling | `70` | |
| 59 | +| `image.repository` | Docker image repository for sparrow-api | `sparrowapi/sparrow-api` | |
| 60 | +| `image.tag` | Image tag to use | `v1` | |
| 61 | +| `service.port` | Port on which the service is exposed | `80` | |
| 62 | +| `service.targetPort` | Port the container listens on | `9000` | |
| 63 | +| `secrets.DB_URL` | MongoDB connection URL | (empty) | |
| 64 | +| `secrets.KAFKA_BROKER` | Kafka broker URL | (empty) | |
| 65 | +| `resources.requests.memory` | Minimum memory guaranteed for the pod | `1024Mi` | |
| 66 | +| `resources.limits.memory` | Maximum memory allowed for the pod | `1648Mi` | |
| 67 | + |
| 68 | +### Example `values.yaml` |
| 69 | + |
| 70 | +Here's an example `values.yaml` configuration file: |
| 71 | + |
| 72 | +```yaml |
| 73 | +replicaCount: 1 |
| 74 | + |
| 75 | +autoscaling: |
| 76 | + enabled: true |
| 77 | + minReplicas: 1 |
| 78 | + maxReplicas: 10 |
| 79 | + targetCPUUtilizationPercentage: 70 |
| 80 | + |
| 81 | +image: |
| 82 | + repository: sparrowapi/sparrow-api |
| 83 | + pullPolicy: IfNotPresent |
| 84 | + tag: v1 |
| 85 | + |
| 86 | +service: |
| 87 | + type: ClusterIP |
| 88 | + port: 80 |
| 89 | + targetPort: 9000 |
| 90 | + |
| 91 | +secrets: |
| 92 | + DB_URL: "mongodb://<username>:<password>@mongodb-service/" |
| 93 | + KAFKA_BROKER: "<KAFKA_URL>:9092" |
| 94 | + |
| 95 | +resources: |
| 96 | + requests: |
| 97 | + memory: 560Mi |
| 98 | + limits: |
| 99 | + memory: 1024Mi |
| 100 | +``` |
| 101 | +
|
| 102 | +## Accessing the Application |
| 103 | +
|
| 104 | +1. **Using Port Forwarding** (for ClusterIP services): |
| 105 | +
|
| 106 | + ```bash |
| 107 | + export POD_NAME=$(kubectl get pods --namespace sparrow-dev -l "app.kubernetes.io/name=sparrow-api" -o jsonpath="{.items[0].metadata.name}") |
| 108 | + kubectl port-forward $POD_NAME 8080:9000 --namespace sparrow-dev |
| 109 | + ``` |
| 110 | + |
| 111 | +2. **Using LoadBalancer IP** (for LoadBalancer services): |
| 112 | + |
| 113 | + ```bash |
| 114 | + kubectl get svc --namespace sparrow-dev sparrow-api -o jsonpath="{.status.loadBalancer.ingress[0].ip}" |
| 115 | + ``` |
| 116 | + |
| 117 | + Copy the IP address and access your application at `http://<LoadBalancer_IP>:80`. |
| 118 | + |
| 119 | + |
| 120 | +## Uninstalling the Chart |
| 121 | + |
| 122 | +To remove the `sparrow-api` release, use the following command: |
| 123 | + |
| 124 | +```bash |
| 125 | +helm uninstall sparrow-api --namespace sparrow-dev |
| 126 | +``` |
| 127 | + |
| 128 | +This will remove all resources associated with the Helm release. |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +Feel free to reach out for any additional guidance or information! |
0 commit comments