From 850bcba5de832f3370de961c0567a765f8d9e855 Mon Sep 17 00:00:00 2001 From: hanshal101 <82961842+hanshal101@users.noreply.github.com> Date: Sat, 10 Feb 2024 23:49:00 +0530 Subject: [PATCH] Add Deployments --- .env | 3 ++- deployments/K8s/jwt-deployment.yaml | 22 ++++++++++++++++++++++ deployments/K8s/jwt-service.yaml | 11 +++++++++++ deployments/K8s/mongodb-deployment.yaml | 19 +++++++++++++++++++ deployments/K8s/mongodb-service.yaml | 11 +++++++++++ internal/db/mongo.go | 3 ++- 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 deployments/K8s/jwt-deployment.yaml create mode 100644 deployments/K8s/jwt-service.yaml create mode 100644 deployments/K8s/mongodb-deployment.yaml create mode 100644 deployments/K8s/mongodb-service.yaml diff --git a/.env b/.env index 99bf579..fd170d5 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ IP="192.168.18.108" -JWT_TOKEN="SECReT" \ No newline at end of file +JWT_TOKEN="SECReT" +MONGO_URI="mongodb://localhost:27017/" \ No newline at end of file diff --git a/deployments/K8s/jwt-deployment.yaml b/deployments/K8s/jwt-deployment.yaml new file mode 100644 index 0000000..9e390da --- /dev/null +++ b/deployments/K8s/jwt-deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: jwt-app +spec: + replicas: 1 + selector: + matchLabels: + app: jwt-app + template: + metadata: + labels: + app: jwt-app + spec: + containers: + - name: jwt + image: hanshal101/jwt + env: + - name: MONGODB_URI + value: "mongodb://mongodb-service:27017/" + ports: + - containerPort: 9876 \ No newline at end of file diff --git a/deployments/K8s/jwt-service.yaml b/deployments/K8s/jwt-service.yaml new file mode 100644 index 0000000..5c48278 --- /dev/null +++ b/deployments/K8s/jwt-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: jwt-service +spec: + selector: + app: jwt-app + ports: + - protocol: TCP + port: 80 + targetPort: 9876 \ No newline at end of file diff --git a/deployments/K8s/mongodb-deployment.yaml b/deployments/K8s/mongodb-deployment.yaml new file mode 100644 index 0000000..8434775 --- /dev/null +++ b/deployments/K8s/mongodb-deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mongodb +spec: + replicas: 1 + selector: + matchLabels: + app: mongodb + template: + metadata: + labels: + app: mongodb + spec: + containers: + - name: mongodb + image: mongo:latest + ports: + - containerPort: 27017 \ No newline at end of file diff --git a/deployments/K8s/mongodb-service.yaml b/deployments/K8s/mongodb-service.yaml new file mode 100644 index 0000000..417acdf --- /dev/null +++ b/deployments/K8s/mongodb-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: mongodb-service +spec: + selector: + app: mongodb + ports: + - protocol: TCP + port: 27017 + targetPort: 27017 \ No newline at end of file diff --git a/internal/db/mongo.go b/internal/db/mongo.go index 774dbe2..e106c47 100644 --- a/internal/db/mongo.go +++ b/internal/db/mongo.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "log" + "os" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) -const uri = "mongodb://localhost:27017/" +var uri = string(os.Getenv("MONGO_URI")) func MongoConnect() { serverAPI := options.ServerAPI(options.ServerAPIVersion1)