From a705b16493f52ba21f473c269e2d2587d6128b51 Mon Sep 17 00:00:00 2001 From: Phil Huang Date: Fri, 18 Aug 2023 02:34:07 +0800 Subject: [PATCH] Add support Kubernetes deployment - Provide k8s/big-agi-deployment.yaml and env-secrert.yaml - Add deploy-k8s.md to explain the installation process --- .gitignore | 5 +- docs/deploy-k8s.md | 81 ++++++++++++++++++++++++ k8s/big-agi-deployment.yaml | 122 ++++++++++++++++++++++++++++++++++++ k8s/env-secret.yaml | 40 ++++++++++++ 4 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 docs/deploy-k8s.md create mode 100644 k8s/big-agi-deployment.yaml create mode 100644 k8s/env-secret.yaml diff --git a/.gitignore b/.gitignore index 2dc2d4f2d..f118110e7 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,7 @@ yarn-error.log* next-env.d.ts # other -.idea/ \ No newline at end of file +.idea/ + +# Ingore k8s/env-secret.yaml +./k8s/env-secret.yaml \ No newline at end of file diff --git a/docs/deploy-k8s.md b/docs/deploy-k8s.md new file mode 100644 index 000000000..7f9d5720b --- /dev/null +++ b/docs/deploy-k8s.md @@ -0,0 +1,81 @@ +# Deploy `big-AGI` with Kubernetes ☸️ + +In this tutorial, we will guide you through the process of deploying a service, Pod, and Deployment in a Kubernetes environment using the kubectl command-line tool. + +## Step 1: Clone the big-AGI repository + +```bash +$ git clone https://github.com/enricoros/big-agi +$ cd ./big-agi/k8s +``` + +## Step 2: Fill in the necessary key information into env-secrert.yaml + +By default, Kubernetes Secrert uses Base64 for encode/encode, so please don't do a git commit after filling in the key to avoid the key leaking. Also, you don't need to fill in all the following parameters, just fill in the necessary ones, just like in `.env.example`. + +```bash +$ vim env-secrert.yaml +$ cat env-secret.yaml +--- +apiVersion: v1 +kind: Secret +metadata: + name: env + namespace: big-agi +type: Opaque +stringData: + ANTHROPIC_API_HOST: "" + ANTHROPIC_API_KEY: "" + ELEVENLABS_API_HOST: "" + ELEVENLABS_API_KEY: "" + ELEVENLABS_VOICE_ID: "" + GOOGLE_CLOUD_API_KEY: "" + GOOGLE_CSE_ID: "" + HELICONE_API_KEY: "" + OPENAI_API_HOST: "api.openai.com" + OPENAI_API_KEY: "sk-xxxxxxxxxxxx" + OPENAI_API_ORG_ID: "" + PRODIA_API_KEY: "" +``` + +## Step 3: Deploy the Kubernetes resources + +By default, all kubernetes resource will be placed in `namespace: big-agi` instead of `namespace: default`. Be sure to switch the correct namespace to see the resources. + +```bash +$ kubectl apply -f big-agi-deployment.yaml -f env-secret.yaml +``` + +## Step 4: Check Resource Status + +The following are the normal outputs, if you encounter abnormal outputs, the you can refer to [Kubernetes - Debug Pods][1]. + +```bash +$ kubectl -n big-agi get svc,pod,deployment +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +service/big-agi ClusterIP 10.0.198.118 3000/TCP 63m + +NAME READY STATUS RESTARTS AGE +pod/big-agi-d4f5d8b7b-jzvq4 1/1 Running 0 39m + +NAME READY UP-TO-DATE AVAILABLE AGE +deployment.apps/big-agi 1/1 1 1 63m +``` + +## Step 5: Test the Service + +The main purpose of the `kubectl port-forward` is to test that big-AGI works properly in Kubernetes, not to formailize itstuse in an production environment. + +If you are looking for a way to expose big-AGI as an public service, see [Kubernetes - Ingress Controller][2] or [Kubernetes - Load Balancer][3]. + +```bash +$ kubectl -n big-agi port-forward service/big-agi 3000 +Forwarding from 127.0.0.1:3000 -> 3000 +Forwarding from [::1]:3000 -> 3000 + +# Open the browser and go to http://localhost:3000 and you should see the big-agi web page +``` + +[1]: https://kubernetes.io/docs/tasks/debug/debug-application/debug-pods/ +[2]: https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/ +[3]: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/ \ No newline at end of file diff --git a/k8s/big-agi-deployment.yaml b/k8s/big-agi-deployment.yaml new file mode 100644 index 000000000..b35184251 --- /dev/null +++ b/k8s/big-agi-deployment.yaml @@ -0,0 +1,122 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: ns-big-agi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: big-agi + name: deployment-big-agi + namespace: ns-big-agi +spec: + replicas: 1 + selector: + matchLabels: + app: big-agi + strategy: {} + template: + metadata: + labels: + app: big-agi + spec: + containers: + - image: ghcr.io/enricoros/big-agi:main + name: big-agi + ports: + - containerPort: 3000 + args: + - next + - start + - -p + - "3000" + env: + - name: OPENAI_API_HOST + valueFrom: + secretKeyRef: + key: OPENAI_API_HOST + name: env + - name: OPENAI_API_KEY + valueFrom: + secretKeyRef: + key: OPENAI_API_KEY + name: env + - name: OPENAI_API_ORG_ID + valueFrom: + secretKeyRef: + key: OPENAI_API_ORG_ID + name: env + - name: HELICONE_API_KEY + valueFrom: + secretKeyRef: + key: HELICONE_API_KEY + name: env + - name: AZURE_OPENAI_API_ENDPOINT + valueFrom: + secretKeyRef: + key: AZURE_OPENAI_API_ENDPOINT + name: env + - name: AZURE_OPENAI_API_KEY + valueFrom: + secretKeyRef: + key: AZURE_OPENAI_API_KEY + name: env + - name: ANTHROPIC_API_HOST + valueFrom: + secretKeyRef: + key: ANTHROPIC_API_HOST + name: env + - name: ANTHROPIC_API_KEY + valueFrom: + secretKeyRef: + key: ANTHROPIC_API_KEY + name: env + - name: ELEVENLABS_API_HOST + valueFrom: + secretKeyRef: + key: ELEVENLABS_API_HOST + name: env + - name: ELEVENLABS_API_KEY + valueFrom: + secretKeyRef: + key: ELEVENLABS_API_KEY + name: env + - name: ELEVENLABS_VOICE_ID + valueFrom: + secretKeyRef: + key: ELEVENLABS_VOICE_ID + name: env + - name: PRODIA_API_KEY + valueFrom: + secretKeyRef: + key: PRODIA_API_KEY + name: env + - name: GOOGLE_CLOUD_API_KEY + valueFrom: + secretKeyRef: + key: GOOGLE_CLOUD_API_KEY + name: env + - name: GOOGLE_CSE_ID + valueFrom: + secretKeyRef: + key: GOOGLE_CSE_ID + name: env + resources: {} + restartPolicy: Always +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: big-agi + name: svc-big-agi + namespace: ns-big-agi +spec: + ports: + - name: "http" + port: 3000 + targetPort: 3000 + selector: + app: big-agi diff --git a/k8s/env-secret.yaml b/k8s/env-secret.yaml new file mode 100644 index 000000000..a530b4bb9 --- /dev/null +++ b/k8s/env-secret.yaml @@ -0,0 +1,40 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + name: env + namespace: ns-big-agi +type: Opaque +stringData: + # [Recommended for local deployments] Backend API key for OpenAI, so that users don't need one (UI > this > '') + OPENAI_API_HOST: "api.openai.com" + # [Optional] Sets the "OpenAI-Organization" header field to support organization users (UI > this > '') + OPENAI_API_KEY: "" + # [Optional] Set the backend host for the OpenAI API, to enable platforms such as Helicone (UI > this > api.openai.com) + OPENAI_API_ORG_ID: "" + + # [Optional, Helicone] Helicone API key: https://www.helicone.ai/keys + HELICONE_API_KEY: "" + + # [Optional] Azure OpenAI Service credentials for the server-side (if set, both must be set) + AZURE_OPENAI_API_ENDPOINT: "" + AZURE_OPENAI_API_KEY: "" + + # [Optional] Anthropic credentials for the server-side + ANTHROPIC_API_HOST: "" + ANTHROPIC_API_KEY: "" + + # [Optional] Enables ElevenLabs credentials on the server side - for optional text-to-speech + ELEVENLABS_API_HOST: "" + ELEVENLABS_API_KEY: "" + ELEVENLABS_VOICE_ID: "" + + # [Optional] Prodia credentials on the server side - for optional image generation + PRODIA_API_KEY: "" + + # [Optional, Search] Google Cloud API Key + # https://console.cloud.google.com/apis/credentials - + GOOGLE_CLOUD_API_KEY: "" + # [Optional, Search] Google Custom/Programmable Search Engine ID + # https://programmablesearchengine.google.com/ + GOOGLE_CSE_ID: ""