Skip to content

Commit

Permalink
fix: posgres basic
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiionutdamian committed Feb 8, 2024
1 parent 6c1f44b commit 70084ba
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 137 deletions.
5 changes: 4 additions & 1 deletion demo-basic-fastapi/.secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ metadata:
namespace: basic-postgres
type: Opaque
data:
redis-password: # add here base64 password
redis-password: # add here base64 password
postgres-password: # add here base64 password
postgres-user: # add here base64 secret
postgres-db: # add here base64 secret
2 changes: 1 addition & 1 deletion demo-basic-fastapi/deploy1_nodeport/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source ../utils.sh

APP_NAME="basic-test-py"
NAMESPACE="basic-ns11"
kubectl delete -f deploy_nodeport.yaml
kubectl delete -f deploy.yaml

# Wait for the pods to be deleted
while true; do
Expand Down
2 changes: 1 addition & 1 deletion demo-basic-fastapi/deploy1_nodeport/full_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source ../utils.sh
MACHINE_IP="192.168.1.55"

# manifest filename
MANIFEST_FILENAME="deploy_nodeport.yaml"
MANIFEST_FILENAME="deploy.yaml"

# Name of the deployment
DEPLOYMENT_NAME="basic-test-py"
Expand Down
5 changes: 3 additions & 2 deletions demo-basic-fastapi/deploy1_nodeport/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
source ../utils.sh

DEPLOYMENT_NAME="basic-test-py"
NAMESPACE="basic-ns12"
NAMESPACE="basic-ns11"
CHECK_INTERVAL=5

kubectl apply -f deploy_nodeport.yaml
kubectl apply -f deploy.yaml

get_ready_replicas() {
kubectl get deployment "$DEPLOYMENT_NAME" -n "$NAMESPACE" -o jsonpath='{.status.readyReplicas}'
Expand Down
2 changes: 1 addition & 1 deletion demo-basic-fastapi/deploy2_ingress/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source ../utils.sh

APP_NAME="basic-test-py"
NAMESPACE="basic-ns12"
kubectl delete -f deploy_with_ingress.yaml
kubectl delete -f deploy.yaml

# Wait for the pods to be deleted
while true; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ metadata:
name: basic-test-py-ingress
namespace: basic-ns12
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
# next part is a bit tricky, but it works
# if rewrite-target is used simply with / then
# the path no matter how long will be rewritten to /
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- http:
paths:
- path: /basic_test
pathType: Prefix
- path: /basic_test(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: basic-test-py-svc
Expand Down
2 changes: 1 addition & 1 deletion demo-basic-fastapi/deploy2_ingress/full_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source ../utils.sh
MACHINE_IP="192.168.1.55"

# manifest filename
MANIFEST_FILENAME="deploy_with_ingress.yaml"
MANIFEST_FILENAME="deploy.yaml"

# Name of the deployment
DEPLOYMENT_NAME="basic-test-py"
Expand Down
3 changes: 2 additions & 1 deletion demo-basic-fastapi/deploy2_ingress/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ source ../utils.sh

DEPLOYMENT_NAME="basic-test-py"
NAMESPACE="basic-ns12"
CHECK_INTERVAL=5

kubectl apply -f deploy_with_ingress.yaml
kubectl apply -f deploy.yaml

get_ready_replicas() {
kubectl get deployment "$DEPLOYMENT_NAME" -n "$NAMESPACE" -o jsonpath='{.status.readyReplicas}'
Expand Down
2 changes: 1 addition & 1 deletion demo-basic-fastapi/deploy2_ingress/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ for i in $(seq 1 10); do
echo " "
done

curl -s $ADDR_PORT/basic_test/stats | jq .
curl -s $ADDR_PORT/stats | jq .
2 changes: 1 addition & 1 deletion demo-basic-fastapi/deploy3_postgres/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source ../utils.sh

APP_NAME="basic-test-py"
NAMESPACE="basic-postgres"
kubectl delete -f deploy_postgres.yaml
kubectl delete -f deploy.yaml

# Wait for the pods to be deleted
while true; do
Expand Down
206 changes: 206 additions & 0 deletions demo-basic-fastapi/deploy3_postgres/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
#########################
### Redis ###
#########################
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: basic-postgres
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:alpine
env:
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: basic-test-app-secrets
key: redis-password
args: ["--requirepass", "$(REDIS_PASSWORD)"]
ports:
- containerPort: 6379
volumeMounts:
- name: redis-storage
mountPath: /data
volumes:
- name: redis-storage
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: basic-postgres
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
---
#########################
### App ###
#########################
apiVersion: apps/v1
kind: Deployment
metadata:
name: basic-test-py
namespace: basic-postgres
spec:
replicas: 4
selector:
matchLabels:
run: basic-test-py
template:
metadata:
labels:
run: basic-test-py
spec:
containers:
- name: test-py-container
image: aidamian/basic_test_fastapi
ports:
- containerPort: 5050
protocol: TCP
# enviroment variables
env:
- name: PORT
value: "5050"
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: basic-test-app-secrets
key: redis-password
---
apiVersion: v1
kind: Service
metadata:
name: basic-test-py-svc
namespace: basic-postgres
spec:
type: ClusterIP
selector:
run: basic-test-py
ports:
- protocol: TCP
port: 5050
nodePort: 5050
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: basic-test-py-ingress
namespace: basic-postgres
annotations:
# next part is a bit tricky, but it works
# if rewrite-target is used simply with / then
# the path no matter how long will be rewritten to /
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- http:
paths:
- path: /pg_test(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: basic-test-py-svc
port:
number: 5050
#########################
### Postgres ###
#########################
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pg-nfs-pv
namespace: basic-postgres
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
nfs:
server: 192.168.1.56
path: "/srv/nfs/k8s/demo-ai-app"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pg-nfs-pvc
namespace: basic-postgres
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
volumeName: pg-nfs-pv
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
namespace: basic-postgres
spec:
serviceName: "postgres"
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:13
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: basic-test-app-secrets
key: postgres-password
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: basic-test-app-secrets
key: postgres-user
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: basic-test-app-secrets
key: postgres-db
ports:
- containerPort: 5432
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: pg-nfs-pvc
---
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: basic-postgres
spec:
ports:
- port: 5432
targetPort: 5432
selector:
app: postgres
Loading

0 comments on commit 70084ba

Please sign in to comment.