Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes Instructions + Support #95

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
auth

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,28 @@ The easiest way to run ChatGPT Clone is by using docker
docker-compose up
```

### Kubernetes

1. Run `kubectl apply -f kubernetes/`. It will create a deployment and ClusterIP Ingress in the namespace "chatgpt-clone"
2. Create a secret containing your OPENAI-API-TOKEN with: `kubectl create secret generic openai-api-key --from-literal=openai-api-key=[YOUR_OPENAI_TOKEN] -n chatgpt-clone`
3. Either change the service to load balancer or ingress (don't forget to password protect it!!), or port-forward it to your local machine: `kubectl port-forward deployment/chatgpt-clone 1338:1338 -n chatgpt-clone`

#### Kubernetes: (optional) Hosting at a domain (ingress)

If you want to host the app at a domain follow these steps:

1. Install - if you haven't already - the nginx ingress
```
helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx
--namespace ingress-nginx
--create-namespace
```
2. Create a basic auth secret which will password protect the app
- `htpasswd -c auth user` (you might need _apt-get install apache2-utils_)
- Enter your password
- This creates a file "auth"
3. "Submit" the password as secret to Kubernetes with:
- `kubectl create secret generic basic-auth --from-file=auth -n chatgpt-clone`
4. Insert your domain in the "kubernetes/nginxingress/chatgpt-clone-ingress.yaml" file.
5. Point your matching domain to your K8s IP
6. `kubectl apply -f kubernetes/nginxingress/`
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"openai_api_base": "https://api.openai.com",
"proxy": {
"enable": true,
"enable": false,
"http": "127.0.0.1:7890",
"https": "127.0.0.1:7890"
}
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ version: '3.5'

services:
chatgpt-clone:
image: chatgpt-clone
image: guestros/chatgpt-clone:latest
container_name: chatgpt-clone
build:
context: .
dockerfile: Dockerfile
ports:
- "1338:1338"
environment:
- OPENAI_API_KEY=akjshdjkhasd
- OPENAI_API_BASE=https://api.openai.com
58 changes: 58 additions & 0 deletions kubernetes/chatgpt-clone-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: v1
kind: Namespace
metadata:
name: chatgpt-clone
---
apiVersion: v1
kind: Service
metadata:
labels:
app: chatgpt-clone
name: chatgpt-clone-service
namespace: chatgpt-clone
spec:
ports:
- name: "1338"
port: 1338
targetPort: 1338
selector:
app: chatgpt-clone
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: chatgpt-clone
name: chatgpt-clone
namespace: chatgpt-clone
spec:
replicas: 1
selector:
matchLabels:
app: chatgpt-clone
template:
metadata:
labels:
app: chatgpt-clone
spec:
containers:
- image: guestros/chatgpt-clone:latest
name: chatgpt-clone
ports:
- containerPort: 1338
resources:
requests:
cpu: 10m
memory: 50Mi
limits:
cpu: "500m"
memory: 500Mi
env:
- name: OPENAI_API_BASE
value: "https://api.openai.com"
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: openai-api-key
key: openai-api-key
restartPolicy: Always
36 changes: 36 additions & 0 deletions kubernetes/nginxingress/chatgpt-clone-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-chatgpt-clone
namespace: chatgpt-clone
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
# nginx.ingress.kubernetes.io/enable-cors: "true"
# nginx.ingress.kubernetes.io/cors-allow-origin: "*"
# nginx.ingress.kubernetes.io/configuration-snippet: |
# more_set_headers "X-Robots-Tag: noindex, nofollow";
cert-manager.io/cluster-issuer: "letsencrypt-prod"
# # type of authentication
nginx.ingress.kubernetes.io/auth-type: basic
# name of the secret that contains the user/password definitions
nginx.ingress.kubernetes.io/auth-secret: basic-auth
# message to display with an appropriate context why the authentication is required
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required'
spec:
ingressClassName: nginx
tls:
- hosts:
- chatgpt.datafortress.cloud
secretName: tls-secret
rules:
- host: chatgpt.datafortress.cloud
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: chatgpt-clone-service
port:
number: 1338
13 changes: 6 additions & 7 deletions server/backend.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from json import dumps
import os
from datetime import datetime
from hashlib import sha256
from json import dumps, loads
from time import time

from flask import request
from hashlib import sha256
from datetime import datetime
from requests import get
from requests import post
from json import loads
import os
from requests import get, post

from server.config import special_instructions

Expand Down