Skip to content

Commit

Permalink
add basic redis and flask project template with deployment and build …
Browse files Browse the repository at this point in the history
…scripts
  • Loading branch information
kPsarakis committed Apr 21, 2022
1 parent 6e84bea commit 5fb1901
Show file tree
Hide file tree
Showing 28 changed files with 693 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.DS_Store
10 changes: 0 additions & 10 deletions code/README.md

This file was deleted.

9 changes: 9 additions & 0 deletions deploy-charts-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

helm repo update

helm install -f helm-config/redis-helm-values.yaml redis bitnami/redis
helm install -f helm-config/nginx-helm-values.yaml nginx ingress-nginx/ingress-nginx
6 changes: 6 additions & 0 deletions deploy-charts-minikube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

helm install -f helm-config/redis-helm-values.yaml redis bitnami/redis
44 changes: 44 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: "3"
services:

gateway:
image: nginx:latest
volumes:
- ./gateway_nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "8000:80"

order-service:
build: ./order
image: order:latest
environment:
- GATEWAY_URL=http://gateway:80
command: gunicorn -b 0.0.0.0:5000 app:app
env_file:
- env/order_redis.env

order-db:
image: redis:latest
command: redis-server --requirepass redis --maxmemory 512mb

stock-service:
build: ./stock
image: stock:latest
command: gunicorn -b 0.0.0.0:5000 app:app
env_file:
- env/stock_redis.env

stock-db:
image: redis:latest
command: redis-server --requirepass redis --maxmemory 512mb

payment-service:
build: ./payment
image: user:latest
command: gunicorn -b 0.0.0.0:5000 app:app
env_file:
- env/payment_redis.env

payment-db:
image: redis:latest
command: redis-server --requirepass redis --maxmemory 512mb
4 changes: 4 additions & 0 deletions env/order_redis.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REDIS_HOST=order-db
REDIS_PORT=6379
REDIS_PASSWORD=redis
REDIS_DB=0
4 changes: 4 additions & 0 deletions env/payment_redis.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REDIS_HOST=payment-db
REDIS_PORT=6379
REDIS_PASSWORD=redis
REDIS_DB=0
4 changes: 4 additions & 0 deletions env/stock_redis.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REDIS_HOST=stock-db
REDIS_PORT=6379
REDIS_PASSWORD=redis
REDIS_DB=0
27 changes: 27 additions & 0 deletions gateway_nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
events { worker_connections 2048;}

http {
upstream order-app {
server order-service:5000;
}
upstream payment-app {
server payment-service:5000;
}
upstream stock-app {
server stock-service:5000;
}
server {
listen 80;
location /orders/ {
proxy_pass http://order-app/;
}
location /payment/ {
proxy_pass http://payment-app/;
}
location /stock/ {
proxy_pass http://stock-app/;
}
access_log /var/log/nginx/server.access.log;
}
access_log /var/log/nginx/access.log;
}
7 changes: 7 additions & 0 deletions helm-config/nginx-helm-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 500m
memory: 1Gi
17 changes: 17 additions & 0 deletions helm-config/redis-helm-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
auth:
password: redis
master:
persistence:
size: 4Gi
resources:
requests:
memory: 4Gi
cpu: 2
replica:
replicaCount: 1
persistence:
size: 4Gi
resources:
requests:
memory: 4Gi
cpu: 2
32 changes: 32 additions & 0 deletions k8s/ingress-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- http:
paths:
- path: /orders/?(.*)
pathType: Prefix
backend:
service:
name: order-service
port:
number: 5000
- path: /stock/?(.*)
pathType: Prefix
backend:
service:
name: stock-service
port:
number: 5000
- path: /payment/?(.*)
pathType: Prefix
backend:
service:
name: user-service
port:
number: 5000
54 changes: 54 additions & 0 deletions k8s/order-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: v1
kind: Service
metadata:
name: order-service
spec:
type: ClusterIP
selector:
component: order
ports:
- port: 5000
name: http
targetPort: 5000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-deployment
spec:
replicas: 1
selector:
matchLabels:
component: order
template:
metadata:
labels:
component: order
spec:
containers:
- name: order
image: order:latest
resources:
limits:
memory: "1Gi"
cpu: "1"
requests:
memory: "1Gi"
cpu: "1"
command: ["gunicorn"]
args: ["-b", "0.0.0.0:5000", "app:app"]
ports:
- containerPort: 5000
env:
- name: USER_SERVICE_URL
value: "user-service"
- name: STOCK_SERVICE_URL
value: "stock-service"
- name: REDIS_HOST
value: redis-master
- name: REDIS_PORT
value: '6379'
- name: REDIS_PASSWORD
value: "redis"
- name: REDIS_DB
value: "0"
50 changes: 50 additions & 0 deletions k8s/stock-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: v1
kind: Service
metadata:
name: stock-service
spec:
type: ClusterIP
selector:
component: stock
ports:
- port: 5000
name: http
targetPort: 5000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: stock-deployment
spec:
replicas: 1
selector:
matchLabels:
component: stock
template:
metadata:
labels:
component: stock
spec:
containers:
- name: stock
image: stock:latest
resources:
limits:
memory: "1Gi"
cpu: "1"
requests:
memory: "1Gi"
cpu: "1"
command: ["gunicorn"]
args: ["-b", "0.0.0.0:5000", "app:app"]
ports:
- containerPort: 5000
env:
- name: REDIS_HOST
value: redis-master
- name: REDIS_PORT
value: '6379'
- name: REDIS_PASSWORD
value: "redis"
- name: REDIS_DB
value: "0"
50 changes: 50 additions & 0 deletions k8s/user-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: v1
kind: Service
metadata:
name: user-service
spec:
type: ClusterIP
selector:
component: user
ports:
- port: 5000
name: http
targetPort: 5000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-deployment
spec:
replicas: 1
selector:
matchLabels:
component: user
template:
metadata:
labels:
component: user
spec:
containers:
- name: user
image: user:latest
resources:
limits:
memory: "1Gi"
cpu: "1"
requests:
memory: "1Gi"
cpu: "1"
command: ["gunicorn"]
args: ["-b", "0.0.0.0:5000", "app:app"]
ports:
- containerPort: 5000
env:
- name: REDIS_HOST
value: redis-master
- name: REDIS_PORT
value: '6379'
- name: REDIS_PASSWORD
value: "redis"
- name: REDIS_DB
value: "0"
11 changes: 11 additions & 0 deletions order/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.10-slim

WORKDIR /home/flask-app

COPY ./requirements.txt .

RUN pip install -r requirements.txt

COPY . .

EXPOSE 5000
Loading

0 comments on commit 5fb1901

Please sign in to comment.