Skip to content

Commit 77cee09

Browse files
authored
Merge pull request #312 from CodeForPhilly/kind-cluster
create: local kind cluster
2 parents fa7103c + e016edb commit 77cee09

File tree

19 files changed

+686
-146
lines changed

19 files changed

+686
-146
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
config
2-
config/env/env.dev
1+
config/*
32
.idea/
3+
env*

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,40 @@ Running pgAdmin:
4646
- The first time you use `pgAdmin` after building the Docker containers you will need to register the server.
4747
The `Host name/address`, `Username` and `Password` are specified in `balancer-main/docker-compose.yml`
4848

49+
## Local Kubernetes Deployment
50+
51+
### Prereqs
52+
53+
- Fill the configmap with the [env vars](./deploy/manifests/balancer/base/configmap.yml)
54+
- Install [Devbox](https://www.jetify.com/devbox)
55+
- Run the following script with admin privileges:
56+
57+
```bash
58+
HOSTNAME="balancertestsite.com"
59+
LOCAL_IP="127.0.0.1"
60+
61+
# Check if the correct line already exists
62+
if grep -q "^$LOCAL_IP[[:space:]]\+$HOSTNAME" /etc/hosts; then
63+
echo "Entry for $HOSTNAME with IP $LOCAL_IP already exists in /etc/hosts"
64+
else
65+
echo "Updating /etc/hosts for $HOSTNAME"
66+
sudo sed -i "/[[:space:]]$HOSTNAME/d" /etc/hosts
67+
echo "$LOCAL_IP $HOSTNAME" | sudo tee -a /etc/hosts
68+
fi
69+
```
70+
71+
### Steps to reproduce
72+
73+
Inside root dir of balancer
74+
75+
```bash
76+
devbox shell
77+
devbox create:cluster
78+
devbox run deploy:balancer
79+
```
80+
81+
The website should be available in [https://balancertestsite.com:30219/](https://balancertestsite.com:30219/)
82+
4983
## Architecture
5084

5185
The Balancer website is a Postgres, Django REST, and React project. The source code layout is:

deploy/kind-config.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
extraPortMappings:
6+
- containerPort: 31880
7+
hostPort: 31880
8+
- containerPort: 30219
9+
hostPort: 30219
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
data:
3+
DEBUG: "1"
4+
SECRET_KEY: "foo"
5+
DJANGO_ALLOWED_HOSTS: "localhost 127.0.0.1 [::1] balancertestsite.com"
6+
SQL_ENGINE: "django.db.backends.postgresql"
7+
SQL_DATABASE: "balancer_dev"
8+
SQL_USER: "balancer"
9+
SQL_PASSWORD: ""
10+
SQL_HOST: ""
11+
SQL_PORT: "5432"
12+
DATABASE: "postgres"
13+
LOGIN_REDIRECT_URL: ""
14+
OPENAI_API_KEY: ""
15+
PINECONE_API_KEY: ""
16+
REACT_APP_API_BASE_URL: "https://balancertestsite.com/"
17+
kind: ConfigMap
18+
metadata:
19+
name: balancer-config
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app: balancer
6+
service: backend
7+
name: balancer
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: balancer
13+
strategy: {}
14+
template:
15+
metadata:
16+
labels:
17+
app: balancer
18+
spec:
19+
containers:
20+
- image: chrissst/balancer
21+
name: balancer
22+
envFrom:
23+
- configMapRef:
24+
name: balancer-config
25+
ports:
26+
- containerPort: 8000
27+
readinessProbe:
28+
httpGet:
29+
path: /
30+
port: 8000
31+
initialDelaySeconds: 30
32+
periodSeconds: 10
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: balancer
5+
annotations:
6+
cert-manager.io/cluster-issuer: "letsencrypt-staging"
7+
spec:
8+
ingressClassName: nginx
9+
tls:
10+
- hosts:
11+
- balancertestsite.com
12+
secretName: balancer-tls
13+
rules:
14+
- host: balancertestsite.com
15+
http:
16+
paths:
17+
- path: /
18+
pathType: Prefix
19+
backend:
20+
service:
21+
name: balancer
22+
port:
23+
number: 80
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- deployment.yml
6+
- service.yml
7+
- configmap.yml
8+
- ingress.yml
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: balancer
5+
labels:
6+
app: balancer
7+
spec:
8+
ports:
9+
- name: http
10+
port: 80
11+
targetPort: 8000
12+
selector:
13+
app: balancer
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- "../../base"
6+
7+
images:
8+
- name: chrissst/balancer
9+
newTag: v1
10+
11+
namespace: balancer
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# clusterissuer-staging.yaml
2+
apiVersion: cert-manager.io/v1
3+
kind: ClusterIssuer
4+
metadata:
5+
name: letsencrypt-staging
6+
spec:
7+
acme:
8+
server: https://acme-staging-v02.api.letsencrypt.org/directory
9+
10+
privateKeySecretRef:
11+
name: letsencrypt-staging-key
12+
solvers:
13+
- http01:
14+
ingress:
15+
class: nginx

0 commit comments

Comments
 (0)