diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index af6b246..7cef36a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/Makefile b/Makefile index 70230f5..9eaf60f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e08912d --- /dev/null +++ b/README.md @@ -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 +``` \ No newline at end of file diff --git a/gobank-api-deployment.yaml b/gobank-api-deployment.yaml new file mode 100644 index 0000000..5472102 --- /dev/null +++ b/gobank-api-deployment.yaml @@ -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 \ No newline at end of file diff --git a/postgres-cluster.yaml b/postgres-cluster.yaml new file mode 100644 index 0000000..bb84009 --- /dev/null +++ b/postgres-cluster.yaml @@ -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 \ No newline at end of file