diff --git a/README.md b/README.md index 06d79e1..0f15e07 100644 --- a/README.md +++ b/README.md @@ -89,4 +89,37 @@ Now we can push these images to DockerHub. ## Use Kubernetes +### Simple deployment +make sure you have run the minikube cluster + +``` + minikube start --memory 12000 --cpus 2 +``` + +Use `cd kubernetes/simple` + +Then apply the following commands. +``` + kubectl apply -f mongo-deployment.yaml + kubectl apply -f mongo-service.yaml + kubectl apply -f node-deploy.yaml + kubectl apply -f node-service.yaml +``` + +Now you can get the address for curl request + + minikube service nodejs-service --url + + For example I got `http://192.168.49.2:30707` + + ``` + curl http://192.168.49.2:30707 + ``` + +This shows out app is working as before. + +``` +$ curl http://192.168.49.2:30707/products +[{"_id":"655a6f85de87398cc510d2e0","name":"xyz","quantity":1,"price":20,"createdAt":"2023-11-19T20:26:45.763Z","updatedAt":"2023-11-19T20:26:45.763Z","__v":0}] +``` diff --git a/kubernetes/simple/mongo-deployment.yaml b/kubernetes/simple/mongo-deployment.yaml new file mode 100644 index 0000000..53181aa --- /dev/null +++ b/kubernetes/simple/mongo-deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mongo-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: mongodb + template: + metadata: + labels: + app: mongodb + spec: + containers: + - name: mongodb + image: pronoob007/mongo:latest + ports: + - containerPort: 27017 \ No newline at end of file diff --git a/kubernetes/simple/mongo-service.yaml b/kubernetes/simple/mongo-service.yaml new file mode 100644 index 0000000..ffa9dfc --- /dev/null +++ b/kubernetes/simple/mongo-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: mongo-service +spec: + selector: + app: mongodb + ports: + - protocol: TCP + port: 27017 + targetPort: 27017 + type: NodePort \ No newline at end of file diff --git a/kubernetes/simple/node-deploy.yaml b/kubernetes/simple/node-deploy.yaml new file mode 100644 index 0000000..389949b --- /dev/null +++ b/kubernetes/simple/node-deploy.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nodejs-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: nodejs + template: + metadata: + labels: + app: nodejs + spec: + containers: + - name: nodejsapp + image: pronoob007/nodejsapp:latest + ports: + - containerPort: 3000 + env: + - name: MONGO_HOST + value: "mongo-service" # Use the service name of the MongoDB deployment + - name: MONGO_PORT + value: "27017" # MongoDB default port \ No newline at end of file diff --git a/kubernetes/simple/node-service.yaml b/kubernetes/simple/node-service.yaml new file mode 100644 index 0000000..e320643 --- /dev/null +++ b/kubernetes/simple/node-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: nodejs-service +spec: + selector: + app: nodejs + ports: + - protocol: TCP + port: 3000 + targetPort: 3000 + type: NodePort \ No newline at end of file