Skip to content

Commit

Permalink
kubernetes is working now
Browse files Browse the repository at this point in the history
Signed-off-by: Your Name <[email protected]>
  • Loading branch information
Your Name committed Nov 19, 2023
1 parent fe23c8d commit d747d23
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
```
19 changes: 19 additions & 0 deletions kubernetes/simple/mongo-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions kubernetes/simple/mongo-service.yaml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions kubernetes/simple/node-deploy.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions kubernetes/simple/node-service.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d747d23

Please sign in to comment.