Skip to content
Merged
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
7 changes: 6 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=long
latest
type=raw,value=latest
flavor: |
lower=true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Build and push Docker image
uses: docker/build-push-action@v7
Expand Down
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,22 @@ mock:
server:
go run main.go

.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1
cluster_stop:
k3d cluster stop gobank-cluster

cluster_start:
k3d cluster start gobank-cluster

cluster_db:
kubectl apply -f postgres-cluster.yaml

cluster_gobank_api:
kubectl apply -f gobank-api-deployment.yaml

cluster_gobank:
k3d cluster create gobank-cluster --api-port 6550 -p "80:80@loadbalancer" -p "443:443@loadbalancer" --agents 2

db_tunnel:
kubectl port-forward svc/gobank-db-rw 5432:5432

.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 cluster_db cluster_start cluster_stop cluster_gobank cluster_gobank_api db_tunnel
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Create gobank cluster via:
# Basic Commands

```bash
make cluster_gobank
```

Create postgres database cluster credentials via:
```bash
kubectl create secret generic db-creds --from-literal=username=root --from-literal=password='YOUR_PASSWORD_HERE'
```

Delete postgres database cluster credentials via:
```bash
kubectl delete secret db-creds
```

Check pods via:
```bash
kubectl get pods
```

Delete a deployment via:
```bash
kubectl delete deployment DEPLOYMENT_NAME
```

Apply a deployment yaml file via:
```bash
kubectl apply -f PATH_TO_YAML
```

Create postgres database cluster via:
```bash
make cluster_db
```

Create gobank-api cluster via:
```bash
make cluster_gobank_api
```

Start cluster via:
```bash
make cluster_start
```

Stop cluster via:
```bash
make cluster_stop
```

Expose a port to database via:
```bash
kubectl port-forward svc/gobank-db-rw 5432:5432
```
73 changes: 73 additions & 0 deletions gobank-api-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: gobank-api
labels:
app: gobank-api
spec:
replicas: 2
selector:
matchLabels:
app: gobank-api
template:
metadata:
labels:
app: gobank-api
spec:
containers:
- name: gobank-api
image: ghcr.io/hypernaser/gobank:latest
ports:
- containerPort: 8080
resources:
requests:
cpu: "100m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "128Mi"
env:
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: db-creds
key: password
- name: PGUSER
valueFrom:
secretKeyRef:
name: db-creds
key: username
- name: DB_SOURCE
value: "postgres://gobank-db-rw:5432/gobank?sslmode=disable"
---
# The Service (The Internal Load Balancer)
apiVersion: v1
kind: Service
metadata:
name: gobank-api-service
spec:
selector:
app: gobank-api
ports:
- protocol: TCP
port: 80
targetPort: 8080
---
# The Ingress (The External Load Balancer)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gobank-ingress
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: gobank-api-service
port:
number: 80
22 changes: 22 additions & 0 deletions postgres-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: gobank-db
spec:
instances: 3

imageName: ghcr.io/cloudnative-pg/postgresql:18.3

bootstrap:
initdb:
database: gobank
owner: root
secret:
name: db-creds

storage:
size: 1Gi

affinity:
enablePodAntiAffinity: true
topologyKey: kubernetes.io/hostname