Skip to content

Commit

Permalink
Add support Kubernetes deployment
Browse files Browse the repository at this point in the history
- Provide k8s/big-agi-deployment.yaml and env-secrert.yaml
- Add deploy-k8s.md to explain the installation process
  • Loading branch information
pichuang committed Aug 21, 2023
1 parent 81bbbdf commit 8bee2f8
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ yarn-error.log*
next-env.d.ts

# other
.idea/
.idea/

# Ingore k8s/env-secret.yaml
./k8s/env-secret.yaml
81 changes: 81 additions & 0 deletions docs/deploy-k8s.md
Original file line number Diff line number Diff line change
@@ -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 <none> 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/
112 changes: 112 additions & 0 deletions k8s/big-agi-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: big-agi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: big-agi
name: big-agi
namespace: 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: 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: 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
- name: HELICONE_API_KEY
valueFrom:
secretKeyRef:
key: HELICONE_API_KEY
name: 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: PRODIA_API_KEY
valueFrom:
secretKeyRef:
key: PRODIA_API_KEY
name: env
resources: {}
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
labels:
app: big-agi
name: big-agi
namespace: big-agi
spec:
ports:
- name: "http"
port: 3000
targetPort: 3000
selector:
app: big-agi
20 changes: 20 additions & 0 deletions k8s/env-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
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: ""
OPENAI_API_ORG_ID: ""
PRODIA_API_KEY: ""

0 comments on commit 8bee2f8

Please sign in to comment.