From 216049fcb66427d9ebce42924ad1bd8d6b392fcb Mon Sep 17 00:00:00 2001 From: river Date: Fri, 1 May 2026 10:48:30 +0300 Subject: [PATCH 1/9] feat: add Docker Buildx setup step in deployment workflow --- .github/workflows/deploy.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index af6b246..2ea1c73 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,6 +36,9 @@ jobs: type=sha,format=long latest + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + - name: Build and push Docker image uses: docker/build-push-action@v7 with: From ee0654023ce762f487c01cc986013b38d99dcbfa Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 09:50:11 +0300 Subject: [PATCH 2/9] feat: add Kubernetes cluster management commands and PostgreSQL cluster configuration --- Makefile | 14 +++++++++++++- README.md | 29 +++++++++++++++++++++++++++++ postgres-cluster.yaml | 22 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 postgres-cluster.yaml diff --git a/Makefile b/Makefile index 70230f5..abb4d80 100644 --- a/Makefile +++ b/Makefile @@ -31,4 +31,16 @@ 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: + k3d cluster create gobank-cluster --api-port 6550 -p "80:80@loadbalancer" -p "443:443@loadbalancer" --agents 2 + +.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 cluster_db cluster_start cluster_stop cluster_gobank diff --git a/README.md b/README.md new file mode 100644 index 0000000..3a03b4d --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +Create gobank cluster via: +```bash +make cluster_gobank +``` + +Create postgres database cluster credentials via: +```bash +kubectl create secret generic db-creds --from-literal=username=root --from-literal=password='' +``` + +Create postgres database cluster via: +```bash +make cluster_db +``` + +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/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 From 9c85eb8b2c64477bc628858d7b4dedf76a0560a9 Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 12:12:54 +0300 Subject: [PATCH 3/9] feat: add create_secret target to Makefile and update README; introduce gobank-api deployment configuration --- .github/workflows/deploy.yml | 4 +- Makefile | 16 +++++++- README.md | 7 +++- gobank-api-deployment.yaml | 73 ++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 gobank-api-deployment.yaml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2ea1c73..7cef36a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -34,7 +34,9 @@ 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 diff --git a/Makefile b/Makefile index abb4d80..0b97e9c 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,14 @@ mock: server: go run main.go +create_secret: + $(eval ENCODED_PWD := $(shell python3 -c "import urllib.parse; print(urllib.parse.quote('$(PWD)', safe=''))")) + @kubectl delete secret db-creds --ignore-not-found + @kubectl create secret generic db-creds \ + --from-literal=username=root \ + --from-literal=password='$(ENCODED_PWD)' + @echo "Secret created with encoded password." + cluster_stop: k3d cluster stop gobank-cluster @@ -40,7 +48,13 @@ cluster_start: 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 -.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 cluster_db cluster_start cluster_stop cluster_gobank +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 create_secret db_tunnel diff --git a/README.md b/README.md index 3a03b4d..f031248 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ make cluster_gobank Create postgres database cluster credentials via: ```bash -kubectl create secret generic db-creds --from-literal=username=root --from-literal=password='' +make create_secret PWD='the_password' ``` Create postgres database cluster via: @@ -13,6 +13,11 @@ Create postgres database cluster via: make cluster_db ``` +Create gobank-api cluster via: +```bash +make cluster_gobank_api +``` + Start cluster via: ```bash make cluster_start diff --git a/gobank-api-deployment.yaml b/gobank-api-deployment.yaml new file mode 100644 index 0000000..5533380 --- /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: DB_USER + valueFrom: + secretKeyRef: + name: db-creds + key: username + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + name: db-creds + key: password + - name: DB_SOURCE + value: "postgresql://$(DB_USER):$(DB_PASSWORD)@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 From bbb21a63340bf9543193ca4d1b38abb701ec94f0 Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 14:17:52 +0300 Subject: [PATCH 4/9] refactor: remove create_secret target from Makefile; update README for secret management; adjust environment variables in gobank-api deployment --- Makefile | 10 +--------- README.md | 22 +++++++++++++++++++++- gobank-api-deployment.yaml | 14 +++++++------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 0b97e9c..9eaf60f 100644 --- a/Makefile +++ b/Makefile @@ -31,14 +31,6 @@ mock: server: go run main.go -create_secret: - $(eval ENCODED_PWD := $(shell python3 -c "import urllib.parse; print(urllib.parse.quote('$(PWD)', safe=''))")) - @kubectl delete secret db-creds --ignore-not-found - @kubectl create secret generic db-creds \ - --from-literal=username=root \ - --from-literal=password='$(ENCODED_PWD)' - @echo "Secret created with encoded password." - cluster_stop: k3d cluster stop gobank-cluster @@ -57,4 +49,4 @@ cluster_gobank: 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 create_secret db_tunnel +.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 index f031248..e1b17cc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,27 @@ make cluster_gobank Create postgres database cluster credentials via: ```bash -make create_secret PWD='the_password' +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: diff --git a/gobank-api-deployment.yaml b/gobank-api-deployment.yaml index 5533380..5472102 100644 --- a/gobank-api-deployment.yaml +++ b/gobank-api-deployment.yaml @@ -27,19 +27,19 @@ spec: cpu: "500m" memory: "128Mi" env: - - name: DB_USER + - name: PGPASSWORD valueFrom: secretKeyRef: name: db-creds - key: username - - name: DB_PASSWORD + key: password + - name: PGUSER valueFrom: secretKeyRef: name: db-creds - key: password + key: username - name: DB_SOURCE - value: "postgresql://$(DB_USER):$(DB_PASSWORD)@gobank-db-rw:5432/gobank?sslmode=disable" - + value: "postgres://gobank-db-rw:5432/gobank?sslmode=disable" +--- # The Service (The Internal Load Balancer) apiVersion: v1 kind: Service @@ -52,7 +52,7 @@ spec: - protocol: TCP port: 80 targetPort: 8080 - +--- # The Ingress (The External Load Balancer) apiVersion: networking.k8s.io/v1 kind: Ingress From 28335858c4fb99e0efed45f9938a41ed7cce768f Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 14:28:19 +0300 Subject: [PATCH 5/9] docs: add section header for basic commands in README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e1b17cc..e08912d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ Create gobank cluster via: +# Basic Commands + ```bash make cluster_gobank ``` From dbddb9f3b92ba1d65613f57b8e4106149e7adc06 Mon Sep 17 00:00:00 2001 From: river Date: Sat, 2 May 2026 14:36:15 +0300 Subject: [PATCH 6/9] chore: remove unused flavor configuration from Docker metadata action --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7cef36a..92b2107 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -35,8 +35,6 @@ jobs: tags: | type=sha,format=long type=raw,value=latest - flavor: | - lower=true - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 From 05bf98295519020d15fa8613954654d93484797a Mon Sep 17 00:00:00 2001 From: river Date: Sun, 3 May 2026 14:58:52 +0300 Subject: [PATCH 7/9] feat: enhance Kubernetes configuration with new cluster management commands and deployment files --- Makefile | 32 +++++++++++++++--- README.md | 30 ++++++++++++++-- file.txt | Bin 32 -> 0 bytes k3d-config.yaml | 17 ++++++++++ .../apps/gobank/gobank-api-deployment.yaml | 18 ++++++++++ k8s/apps/gobank/kustomization.yaml | 8 +++++ k8s/apps/gobank/namespace.yaml | 4 +++ .../apps/gobank/postgres-cluster.yaml | 13 +++++-- k8s/base/cnpg-operator/kustomization.yaml | 5 +++ 9 files changed, 116 insertions(+), 11 deletions(-) delete mode 100644 file.txt create mode 100644 k3d-config.yaml rename gobank-api-deployment.yaml => k8s/apps/gobank/gobank-api-deployment.yaml (75%) create mode 100644 k8s/apps/gobank/kustomization.yaml create mode 100644 k8s/apps/gobank/namespace.yaml rename postgres-cluster.yaml => k8s/apps/gobank/postgres-cluster.yaml (71%) create mode 100644 k8s/base/cnpg-operator/kustomization.yaml diff --git a/Makefile b/Makefile index 9eaf60f..f59b69b 100644 --- a/Makefile +++ b/Makefile @@ -38,15 +38,37 @@ cluster_start: k3d cluster start gobank-cluster cluster_db: - kubectl apply -f postgres-cluster.yaml + kubectl apply -f ./k8s/apps/gobank/postgres-cluster.yaml --server-side cluster_gobank_api: - kubectl apply -f gobank-api-deployment.yaml + kubectl apply -f ./k8s/apps/gobank/gobank-api-deployment.yaml --server-side -cluster_gobank: - k3d cluster create gobank-cluster --api-port 6550 -p "80:80@loadbalancer" -p "443:443@loadbalancer" --agents 2 +apply_cluster_configs: # this is really hacky but we'll roll with it for now. If an issue arises, then rerun the command + kubectl apply -k ./k8s/base/cnpg-operator --server-side + sleep 20 + kubectl wait --for condition=established --timeout=60s crd/clusters.postgresql.cnpg.io + kubectl apply -k ./k8s/apps/gobank --server-side + +cluster: + k3d cluster create --config ./k3d-config.yaml + +delete_cluster_gobank: + k3d cluster delete gobank-cluster + +namespace: + kubectl apply -f k8s/apps/gobank/namespace.yaml + +create_creds: namespace + @read -p "Enter DB Password: " pwd; \ + kubectl create secret generic db-creds \ + --from-literal=username=root \ + --from-literal=password=$$pwd \ + --namespace gobank \ + --dry-run=client -o yaml | kubectl apply -f - + +setup: create_creds apply_cluster_configs 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 +.PHONY: postgres createdb dropdb migrateup migratedown sqlc test mock server migrateup1 migratedown1 cluster_db cluster_start cluster_stop cluster cluster_gobank_api db_tunnel delete_cluster_gobank apply_cluster_configs namespace create_creds setup diff --git a/README.md b/README.md index e08912d..db79095 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,32 @@ -Create gobank cluster via: # Basic Commands +Create gobank cluster via: +```bash +make cluster +``` + +Delete gobank cluster via: +```bash +make delete_cluster_gobank +``` + +Make initial setup via: ```bash -make cluster_gobank +make setup ``` Create postgres database cluster credentials via: ```bash -kubectl create secret generic db-creds --from-literal=username=root --from-literal=password='YOUR_PASSWORD_HERE' +make create_creds +``` +or manual via (make sure namespace exists first): +```bash +kubectl create secret generic db-creds --namespace gobank --from-literal=username=root --from-literal=password='YOUR_PASSWORD_HERE' +``` + +Create namespace via: +```bash +make namespace ``` Delete postgres database cluster credentials via: @@ -30,6 +49,11 @@ Apply a deployment yaml file via: kubectl apply -f PATH_TO_YAML ``` +Apply all cluster configs: +```bash +make apply_cluster_configs +``` + Create postgres database cluster via: ```bash make cluster_db diff --git a/file.txt b/file.txt deleted file mode 100644 index 48bccc4a7c16484dde10d880443634bd5e2786d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32 qcmV+*0N?-FSpbfv+Uihl?E~ZAn}FkxR7s4Y11p!DfJu4Pz#k+ahY)W7 diff --git a/k3d-config.yaml b/k3d-config.yaml new file mode 100644 index 0000000..07d9504 --- /dev/null +++ b/k3d-config.yaml @@ -0,0 +1,17 @@ +apiVersion: k3d.io/v1alpha5 +kind: Simple +metadata: + name: gobank-cluster +servers: 1 +agents: 2 +image: rancher/k3s:v1.36.0-rc3-k3s1 +kubeAPI: + hostIP: "0.0.0.0" + hostPort: "6550" +ports: + - port: 80:80 + nodeFilters: + - loadbalancer + - port: 443:443 + nodeFilters: + - loadbalancer \ No newline at end of file diff --git a/gobank-api-deployment.yaml b/k8s/apps/gobank/gobank-api-deployment.yaml similarity index 75% rename from gobank-api-deployment.yaml rename to k8s/apps/gobank/gobank-api-deployment.yaml index 5472102..060fdbd 100644 --- a/gobank-api-deployment.yaml +++ b/k8s/apps/gobank/gobank-api-deployment.yaml @@ -14,6 +14,24 @@ spec: labels: app: gobank-api spec: + initContainers: + - name: wait-for-db + image: postgres:alpine + command: + - sh + - -c + - | + echo "Waiting for gobank-db-rw to be ready..." + until pg_isready -h gobank-db-rw -p 5432 -U $PGUSER; do + sleep 2 + done + echo "Database is ready!" + env: + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-creds + key: username containers: - name: gobank-api image: ghcr.io/hypernaser/gobank:latest diff --git a/k8s/apps/gobank/kustomization.yaml b/k8s/apps/gobank/kustomization.yaml new file mode 100644 index 0000000..6b992fe --- /dev/null +++ b/k8s/apps/gobank/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: gobank + +resources: + - namespace.yaml + - postgres-cluster.yaml + - gobank-api-deployment.yaml \ No newline at end of file diff --git a/k8s/apps/gobank/namespace.yaml b/k8s/apps/gobank/namespace.yaml new file mode 100644 index 0000000..6594277 --- /dev/null +++ b/k8s/apps/gobank/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: gobank \ No newline at end of file diff --git a/postgres-cluster.yaml b/k8s/apps/gobank/postgres-cluster.yaml similarity index 71% rename from postgres-cluster.yaml rename to k8s/apps/gobank/postgres-cluster.yaml index bb84009..efe00e6 100644 --- a/postgres-cluster.yaml +++ b/k8s/apps/gobank/postgres-cluster.yaml @@ -3,10 +3,17 @@ kind: Cluster metadata: name: gobank-db spec: - instances: 3 - + instances: 2 imageName: ghcr.io/cloudnative-pg/postgresql:18.3 - + + resources: + requests: + memory: "256Mi" + cpu: "100m" + limits: + memory: "512Mi" + cpu: "500m" + bootstrap: initdb: database: gobank diff --git a/k8s/base/cnpg-operator/kustomization.yaml b/k8s/base/cnpg-operator/kustomization.yaml new file mode 100644 index 0000000..5bc3772 --- /dev/null +++ b/k8s/base/cnpg-operator/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-1.29/releases/cnpg-1.29.0.yaml \ No newline at end of file From 09316cea8b5e459fe529ed51523febe97bdf1e5b Mon Sep 17 00:00:00 2001 From: river Date: Sun, 3 May 2026 15:22:46 +0300 Subject: [PATCH 8/9] chore: remove deprecated Kubernetes deployment and PostgreSQL cluster configuration files --- gobank-api-deployment.yaml | 73 -------------------------------------- postgres-cluster.yaml | 22 ------------ 2 files changed, 95 deletions(-) delete mode 100644 gobank-api-deployment.yaml delete mode 100644 postgres-cluster.yaml diff --git a/gobank-api-deployment.yaml b/gobank-api-deployment.yaml deleted file mode 100644 index 5472102..0000000 --- a/gobank-api-deployment.yaml +++ /dev/null @@ -1,73 +0,0 @@ -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 deleted file mode 100644 index bb84009..0000000 --- a/postgres-cluster.yaml +++ /dev/null @@ -1,22 +0,0 @@ -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 From 0f8dd510dd632b1bf31fdcc1a07e96c7928d8fc0 Mon Sep 17 00:00:00 2001 From: river Date: Tue, 5 May 2026 16:08:44 +0300 Subject: [PATCH 9/9] feat: separate Kubernetes deployment, service, and ingress configurations for gobank API --- k3d-config.yaml | 2 +- ...nk-api-deployment.yaml => deployment.yaml} | 34 +------------------ k8s/apps/gobank/ingress.yaml | 17 ++++++++++ k8s/apps/gobank/kustomization.yaml | 4 ++- k8s/apps/gobank/service.yaml | 11 ++++++ 5 files changed, 33 insertions(+), 35 deletions(-) rename k8s/apps/gobank/{gobank-api-deployment.yaml => deployment.yaml} (69%) create mode 100644 k8s/apps/gobank/ingress.yaml create mode 100644 k8s/apps/gobank/service.yaml diff --git a/k3d-config.yaml b/k3d-config.yaml index 07d9504..1ff0867 100644 --- a/k3d-config.yaml +++ b/k3d-config.yaml @@ -6,7 +6,7 @@ servers: 1 agents: 2 image: rancher/k3s:v1.36.0-rc3-k3s1 kubeAPI: - hostIP: "0.0.0.0" + hostIP: "127.0.0.1" hostPort: "6550" ports: - port: 80:80 diff --git a/k8s/apps/gobank/gobank-api-deployment.yaml b/k8s/apps/gobank/deployment.yaml similarity index 69% rename from k8s/apps/gobank/gobank-api-deployment.yaml rename to k8s/apps/gobank/deployment.yaml index 060fdbd..70dc13f 100644 --- a/k8s/apps/gobank/gobank-api-deployment.yaml +++ b/k8s/apps/gobank/deployment.yaml @@ -56,36 +56,4 @@ spec: 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 + value: "postgres://gobank-db-rw:5432/gobank?sslmode=disable" \ No newline at end of file diff --git a/k8s/apps/gobank/ingress.yaml b/k8s/apps/gobank/ingress.yaml new file mode 100644 index 0000000..8a461de --- /dev/null +++ b/k8s/apps/gobank/ingress.yaml @@ -0,0 +1,17 @@ +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 diff --git a/k8s/apps/gobank/kustomization.yaml b/k8s/apps/gobank/kustomization.yaml index 6b992fe..eb19900 100644 --- a/k8s/apps/gobank/kustomization.yaml +++ b/k8s/apps/gobank/kustomization.yaml @@ -5,4 +5,6 @@ namespace: gobank resources: - namespace.yaml - postgres-cluster.yaml - - gobank-api-deployment.yaml \ No newline at end of file + - gobank-api-deployment.yaml + - service.yaml + - ingress.yaml \ No newline at end of file diff --git a/k8s/apps/gobank/service.yaml b/k8s/apps/gobank/service.yaml new file mode 100644 index 0000000..e3c19db --- /dev/null +++ b/k8s/apps/gobank/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: gobank-api-service +spec: + selector: + app: gobank-api + ports: + - protocol: TCP + port: 80 + targetPort: 8080