Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use the official Node.js 14 image as the base image
FROM node:14

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code to the working directory
COPY . .

# Expose port 4000 (assuming your Node.js application listens on this port)
EXPOSE 4000

# Set the command to run when the container starts
CMD ["npm", "start"]
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Simple Node Express Hello World App


![localhost:3000](/public/images/localhost_3000.png?raw=true "Node & Express")
![localhost:4000](/public/images/localhost_4000.png?raw=true "Node & Express")

# Steps :
```
Expand All @@ -10,6 +10,25 @@
npm install
npm start

Go to localhost:3000
Go to localhost:4000

```
# Prerequisites :
## Running kubernetes cluster
make sure you have running kubernetes cluster on cloud or on hosted locally (kind - minikube ..etc)
## Install liknkerd
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-linkerd-with-kubernetes
## Install Linkerd-SMI extension for canary deployment
https://linkerd.io/2.15/tasks/linkerd-smi/#install-the-linkerd-smi-extension

# Usage :

```
kubectl create ns <ns-name>
kubectl annotate ns <ns-name> linkerd.io/inject=enabled
cd node-express-hello-world/k8s
kubectl apply -f version-I -n <ns-name>
kubectl apply -f version-II -n <ns-name>
kubectl apply -f traffic-split.yaml -n <ns-name>

```
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ app.use(express.static(__dirname + '/public'));

app.get('/',routes.home);

var port = process.env.PORT || 3000;
var port = process.env.PORT || 4000;

var server=app.listen(port,function(req,res){
console.log("Catch the action at http://localhost:"+port);
Expand Down
12 changes: 12 additions & 0 deletions k8s/traffic-split.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: split.smi-spec.io/v1alpha1
kind: TrafficSplit
metadata:
name: my-app-traffic-split
namespace: node
spec:
service: my-app-service
backends:
- service: my-app-service-v1
weight: 50m
- service: my-app-service-v2
weight: 50m
23 changes: 23 additions & 0 deletions k8s/version-I/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-v1
spec:
replicas: 1
selector:
matchLabels:
app: my-app
version: v1
template:
metadata:
labels:
app: my-app
version: v1
annotations:
linkerd.io/inject: enabled
spec:
containers:
- name: my-app
image: ahmednageh08/node-app:v1
ports:
- containerPort: 4000
12 changes: 12 additions & 0 deletions k8s/version-I/svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: my-app-service-v1
spec:
selector:
app: my-app
version: v1
ports:
- protocol: TCP
port: 4000
targetPort: 4000
23 changes: 23 additions & 0 deletions k8s/version-II/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-v2
spec:
replicas: 1
selector:
matchLabels:
app: my-app
version: v2
template:
metadata:
labels:
app: my-app
version: v2
annotations:
linkerd.io/inject: enabled
spec:
containers:
- name: my-app
image: ahmednageh08/node-app:v2
ports:
- containerPort: 4000
12 changes: 12 additions & 0 deletions k8s/version-II/svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: my-app-service-v2
spec:
selector:
app: my-app
version: v2
ports:
- protocol: TCP
port: 4000
targetPort: 4000
28 changes: 28 additions & 0 deletions playbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- name: Deploy and run Node.js application
hosts: all
become: true

tasks:
- name: Clone Node.js application repository
git:
repo: https://github.com/AhmedNageh08/node-express-hello-world.git
dest: /opt/node-express-hello-world
version: master
force: yes

- name: Install npm package
apt:
name: npm
state: present

- name: Install App dependencies
command: npm install
args:
chdir: /opt/node-express-hello-world

- name: Start Node.js application in detached mode
shell: >
cd /opt/node-express-hello-world &&
nohup npm start &> /dev/null &
echo $! > /var/run/node-express-hello-world.pid

2 changes: 1 addition & 1 deletion views/home.ejs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<h1 align="center">Heyyo :)</h1>
<h1 align="center">Hey Devops Team :)</h1>