From e5378b513ea42e45bd3820283d73b80cf9631a64 Mon Sep 17 00:00:00 2001 From: Nageh Date: Thu, 29 Feb 2024 16:59:46 +0200 Subject: [PATCH 01/14] add Dockerfile --- Dockerfile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..30ca2e2 --- /dev/null +++ b/Dockerfile @@ -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 3000 (assuming your Node.js application listens on this port) +EXPOSE 3000 + +# Set the command to run when the container starts +CMD ["npm", "start"] \ No newline at end of file From 7193625bad8d076288ffafc32a3bf560026fc997 Mon Sep 17 00:00:00 2001 From: Nageh Date: Thu, 29 Feb 2024 19:28:19 +0200 Subject: [PATCH 02/14] add kubernetes manifests --- version-I/deploy.yaml | 21 +++++++++++++++++++++ version-I/svc.yaml | 13 +++++++++++++ version-II/deploy.yaml | 21 +++++++++++++++++++++ version-II/svc.yaml | 13 +++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 version-I/deploy.yaml create mode 100644 version-I/svc.yaml create mode 100644 version-II/deploy.yaml create mode 100644 version-II/svc.yaml diff --git a/version-I/deploy.yaml b/version-I/deploy.yaml new file mode 100644 index 0000000..0ae9d9e --- /dev/null +++ b/version-I/deploy.yaml @@ -0,0 +1,21 @@ +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 + spec: + containers: + - name: my-app + image: ahmednageh08/node-app:v1 + ports: + - containerPort: 3000 \ No newline at end of file diff --git a/version-I/svc.yaml b/version-I/svc.yaml new file mode 100644 index 0000000..b027cd0 --- /dev/null +++ b/version-I/svc.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: my-app-service-v1 +spec: + selector: + app: my-app + version: v1 + ports: + - protocol: TCP + port: 3000 + targetPort: 3000 + type: NodePort \ No newline at end of file diff --git a/version-II/deploy.yaml b/version-II/deploy.yaml new file mode 100644 index 0000000..ff92d56 --- /dev/null +++ b/version-II/deploy.yaml @@ -0,0 +1,21 @@ +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 + spec: + containers: + - name: my-app + image: ahmednageh08/node-app:v2 + ports: + - containerPort: 3000 \ No newline at end of file diff --git a/version-II/svc.yaml b/version-II/svc.yaml new file mode 100644 index 0000000..241f28a --- /dev/null +++ b/version-II/svc.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: my-app-service-v2 +spec: + selector: + app: my-app + version: v2 + ports: + - protocol: TCP + port: 3000 + targetPort: 3001 + type: NodePort \ No newline at end of file From 3606f07a8242a503d8cec81c29545cd7219b12cf Mon Sep 17 00:00:00 2001 From: Nageh Date: Sat, 2 Mar 2024 19:23:29 +0200 Subject: [PATCH 03/14] add load balancing --- version-I/svc.yaml | 6 +++++- version-II/svc.yaml | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/version-I/svc.yaml b/version-I/svc.yaml index b027cd0..c6c2c86 100644 --- a/version-I/svc.yaml +++ b/version-I/svc.yaml @@ -10,4 +10,8 @@ spec: - protocol: TCP port: 3000 targetPort: 3000 - type: NodePort \ No newline at end of file + externalTrafficPolicy: Local + healthCheckNodePort: 30931 + endpoints: + - ip: 10.244.0.5 + port: 3000 \ No newline at end of file diff --git a/version-II/svc.yaml b/version-II/svc.yaml index 241f28a..e36f3d2 100644 --- a/version-II/svc.yaml +++ b/version-II/svc.yaml @@ -1,13 +1,17 @@ apiVersion: v1 kind: Service metadata: - name: my-app-service-v2 + name: my-app-service spec: selector: app: my-app - version: v2 + version: v1 ports: - protocol: TCP port: 3000 - targetPort: 3001 - type: NodePort \ No newline at end of file + targetPort: 3000 + externalTrafficPolicy: Local + healthCheckNodePort: 30932 + endpoints: + - ip: 10.244.1.6 + port: 3000 \ No newline at end of file From c3e22161a73d286f93ebe695c72d9b6a9ba7f046 Mon Sep 17 00:00:00 2001 From: Ahmed Nageh Date: Sat, 2 Mar 2024 19:27:48 +0200 Subject: [PATCH 04/14] Update svc.yaml --- version-II/svc.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version-II/svc.yaml b/version-II/svc.yaml index e36f3d2..508109d 100644 --- a/version-II/svc.yaml +++ b/version-II/svc.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Service metadata: - name: my-app-service + name: my-app-service-v2 spec: selector: app: my-app @@ -14,4 +14,4 @@ spec: healthCheckNodePort: 30932 endpoints: - ip: 10.244.1.6 - port: 3000 \ No newline at end of file + port: 3000 From 2336830de6686a854f7a26eca8d4437c5972607a Mon Sep 17 00:00:00 2001 From: Ahmed Nageh Date: Sat, 2 Mar 2024 19:28:31 +0200 Subject: [PATCH 05/14] Update svc.yaml --- version-II/svc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version-II/svc.yaml b/version-II/svc.yaml index 508109d..a79bd70 100644 --- a/version-II/svc.yaml +++ b/version-II/svc.yaml @@ -5,7 +5,7 @@ metadata: spec: selector: app: my-app - version: v1 + version: v2 ports: - protocol: TCP port: 3000 From 3701c745cb493f570f6c8e551c7cf1df32579b3c Mon Sep 17 00:00:00 2001 From: Nageh Date: Sat, 2 Mar 2024 22:47:29 +0200 Subject: [PATCH 06/14] add linkerd mesh service --- k8s/linkerd.yaml | 14 ++++++++++++++ {version-I => k8s/version-I}/deploy.yaml | 0 {version-I => k8s/version-I}/svc.yaml | 6 +----- {version-II => k8s/version-II}/deploy.yaml | 0 {version-II => k8s/version-II}/svc.yaml | 6 +----- 5 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 k8s/linkerd.yaml rename {version-I => k8s/version-I}/deploy.yaml (100%) rename {version-I => k8s/version-I}/svc.yaml (62%) rename {version-II => k8s/version-II}/deploy.yaml (100%) rename {version-II => k8s/version-II}/svc.yaml (62%) diff --git a/k8s/linkerd.yaml b/k8s/linkerd.yaml new file mode 100644 index 0000000..221b90a --- /dev/null +++ b/k8s/linkerd.yaml @@ -0,0 +1,14 @@ +apiVersion: linkerd.io/v1alpha1 +kind: ServiceProfile +metadata: + name: my-app-service +spec: + routes: + - condition: + pathRegex: / + name: "my-app-v1" + weight: 50 + - condition: + pathRegex: / + name: "my-app-v2" + weight: 50 \ No newline at end of file diff --git a/version-I/deploy.yaml b/k8s/version-I/deploy.yaml similarity index 100% rename from version-I/deploy.yaml rename to k8s/version-I/deploy.yaml diff --git a/version-I/svc.yaml b/k8s/version-I/svc.yaml similarity index 62% rename from version-I/svc.yaml rename to k8s/version-I/svc.yaml index c6c2c86..b027cd0 100644 --- a/version-I/svc.yaml +++ b/k8s/version-I/svc.yaml @@ -10,8 +10,4 @@ spec: - protocol: TCP port: 3000 targetPort: 3000 - externalTrafficPolicy: Local - healthCheckNodePort: 30931 - endpoints: - - ip: 10.244.0.5 - port: 3000 \ No newline at end of file + type: NodePort \ No newline at end of file diff --git a/version-II/deploy.yaml b/k8s/version-II/deploy.yaml similarity index 100% rename from version-II/deploy.yaml rename to k8s/version-II/deploy.yaml diff --git a/version-II/svc.yaml b/k8s/version-II/svc.yaml similarity index 62% rename from version-II/svc.yaml rename to k8s/version-II/svc.yaml index a79bd70..a32c554 100644 --- a/version-II/svc.yaml +++ b/k8s/version-II/svc.yaml @@ -10,8 +10,4 @@ spec: - protocol: TCP port: 3000 targetPort: 3000 - externalTrafficPolicy: Local - healthCheckNodePort: 30932 - endpoints: - - ip: 10.244.1.6 - port: 3000 + type: NodePort \ No newline at end of file From ab2e511f09bd802d10cf5523447a129f7053c20d Mon Sep 17 00:00:00 2001 From: Nageh Date: Sun, 3 Mar 2024 00:05:13 +0200 Subject: [PATCH 07/14] update linkerd mesh service --- k8s/linkerd.yaml | 14 -------------- k8s/traffic-split.yaml | 12 ++++++++++++ k8s/version-I/svc.yaml | 3 +-- k8s/version-II/svc.yaml | 1 - 4 files changed, 13 insertions(+), 17 deletions(-) delete mode 100644 k8s/linkerd.yaml create mode 100644 k8s/traffic-split.yaml diff --git a/k8s/linkerd.yaml b/k8s/linkerd.yaml deleted file mode 100644 index 221b90a..0000000 --- a/k8s/linkerd.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: linkerd.io/v1alpha1 -kind: ServiceProfile -metadata: - name: my-app-service -spec: - routes: - - condition: - pathRegex: / - name: "my-app-v1" - weight: 50 - - condition: - pathRegex: / - name: "my-app-v2" - weight: 50 \ No newline at end of file diff --git a/k8s/traffic-split.yaml b/k8s/traffic-split.yaml new file mode 100644 index 0000000..4a4e3d3 --- /dev/null +++ b/k8s/traffic-split.yaml @@ -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 \ No newline at end of file diff --git a/k8s/version-I/svc.yaml b/k8s/version-I/svc.yaml index b027cd0..f9ea56a 100644 --- a/k8s/version-I/svc.yaml +++ b/k8s/version-I/svc.yaml @@ -9,5 +9,4 @@ spec: ports: - protocol: TCP port: 3000 - targetPort: 3000 - type: NodePort \ No newline at end of file + targetPort: 3000 \ No newline at end of file diff --git a/k8s/version-II/svc.yaml b/k8s/version-II/svc.yaml index a32c554..a2f4fba 100644 --- a/k8s/version-II/svc.yaml +++ b/k8s/version-II/svc.yaml @@ -10,4 +10,3 @@ spec: - protocol: TCP port: 3000 targetPort: 3000 - type: NodePort \ No newline at end of file From 578df0b10f7af352ef013dd88bfb55116ec1e035 Mon Sep 17 00:00:00 2001 From: Nageh Date: Sun, 3 Mar 2024 00:33:43 +0200 Subject: [PATCH 08/14] update Readme --- README.md | 16 ++++++++++++++++ k8s/version-I/deploy.yaml | 2 ++ k8s/version-II/deploy.yaml | 2 ++ 3 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 580ec91..22ede10 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,19 @@ Go to localhost:3000 ``` +# 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 + kubectl annotate ns linkerd.io/inject=enabled + cd node-express-hello-world/k8s + kubectl apply -f version-I -n + kubectl apply -f version-II -n + kubectl apply -f traffic-split.yaml -n +''' \ No newline at end of file diff --git a/k8s/version-I/deploy.yaml b/k8s/version-I/deploy.yaml index 0ae9d9e..b332db7 100644 --- a/k8s/version-I/deploy.yaml +++ b/k8s/version-I/deploy.yaml @@ -13,6 +13,8 @@ spec: labels: app: my-app version: v1 + annotations: + linkerd.io/inject: enabled spec: containers: - name: my-app diff --git a/k8s/version-II/deploy.yaml b/k8s/version-II/deploy.yaml index ff92d56..c1850a1 100644 --- a/k8s/version-II/deploy.yaml +++ b/k8s/version-II/deploy.yaml @@ -13,6 +13,8 @@ spec: labels: app: my-app version: v2 + annotations: + linkerd.io/inject: enabled spec: containers: - name: my-app From 394dfebe440e7bb12eedeeb8fb05be9337c76ab7 Mon Sep 17 00:00:00 2001 From: Nageh Date: Sun, 3 Mar 2024 00:37:23 +0200 Subject: [PATCH 09/14] update Readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 22ede10..735578a 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,11 @@ https://www.digitalocean.com/community/tutorials/how-to-install-and-use-linkerd- https://linkerd.io/2.15/tasks/linkerd-smi/#install-the-linkerd-smi-extension # Usage : -'''kubectl create ns + +```kubectl create ns kubectl annotate ns linkerd.io/inject=enabled cd node-express-hello-world/k8s kubectl apply -f version-I -n kubectl apply -f version-II -n kubectl apply -f traffic-split.yaml -n -''' \ No newline at end of file +``` \ No newline at end of file From 50a70a74192d183ed2960f443447d38f015ffd70 Mon Sep 17 00:00:00 2001 From: Ahmed Nageh Date: Sun, 3 Mar 2024 00:38:28 +0200 Subject: [PATCH 10/14] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 735578a..7e64e81 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,12 @@ https://linkerd.io/2.15/tasks/linkerd-smi/#install-the-linkerd-smi-extension # Usage : -```kubectl create ns +``` + kubectl create ns kubectl annotate ns linkerd.io/inject=enabled cd node-express-hello-world/k8s kubectl apply -f version-I -n kubectl apply -f version-II -n kubectl apply -f traffic-split.yaml -n -``` \ No newline at end of file + +``` From e0498d2ba7eb93ac932b456458455f8907e2ecfa Mon Sep 17 00:00:00 2001 From: Afaqy Date: Mon, 8 Jul 2024 21:31:29 +0300 Subject: [PATCH 11/14] update port --- Dockerfile | 4 ++-- README.md | 4 ++-- app.js | 2 +- k8s/version-I/deploy.yaml | 2 +- k8s/version-I/svc.yaml | 4 ++-- k8s/version-II/deploy.yaml | 2 +- k8s/version-II/svc.yaml | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 30ca2e2..a5dc6b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,8 @@ RUN npm install # Copy the rest of the application code to the working directory COPY . . -# Expose port 3000 (assuming your Node.js application listens on this port) -EXPOSE 3000 +# 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"] \ No newline at end of file diff --git a/README.md b/README.md index 7e64e81..7185ed4 100644 --- a/README.md +++ b/README.md @@ -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 : ``` @@ -10,7 +10,7 @@ npm install npm start - Go to localhost:3000 + Go to localhost:4000 ``` # Prerequisites : diff --git a/app.js b/app.js index 643cb36..d07d801 100644 --- a/app.js +++ b/app.js @@ -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); diff --git a/k8s/version-I/deploy.yaml b/k8s/version-I/deploy.yaml index b332db7..f90aeaa 100644 --- a/k8s/version-I/deploy.yaml +++ b/k8s/version-I/deploy.yaml @@ -20,4 +20,4 @@ spec: - name: my-app image: ahmednageh08/node-app:v1 ports: - - containerPort: 3000 \ No newline at end of file + - containerPort: 4000 \ No newline at end of file diff --git a/k8s/version-I/svc.yaml b/k8s/version-I/svc.yaml index f9ea56a..b2ec21d 100644 --- a/k8s/version-I/svc.yaml +++ b/k8s/version-I/svc.yaml @@ -8,5 +8,5 @@ spec: version: v1 ports: - protocol: TCP - port: 3000 - targetPort: 3000 \ No newline at end of file + port: 4000 + targetPort: 4000 \ No newline at end of file diff --git a/k8s/version-II/deploy.yaml b/k8s/version-II/deploy.yaml index c1850a1..993100c 100644 --- a/k8s/version-II/deploy.yaml +++ b/k8s/version-II/deploy.yaml @@ -20,4 +20,4 @@ spec: - name: my-app image: ahmednageh08/node-app:v2 ports: - - containerPort: 3000 \ No newline at end of file + - containerPort: 4000 \ No newline at end of file diff --git a/k8s/version-II/svc.yaml b/k8s/version-II/svc.yaml index a2f4fba..4d7cf6f 100644 --- a/k8s/version-II/svc.yaml +++ b/k8s/version-II/svc.yaml @@ -8,5 +8,5 @@ spec: version: v2 ports: - protocol: TCP - port: 3000 - targetPort: 3000 + port: 4000 + targetPort: 4000 From f291d5c90b1024fb25f2af0541cbb6f80cca3e71 Mon Sep 17 00:00:00 2001 From: Ahmed Nageh Date: Thu, 11 Jul 2024 16:49:08 +0300 Subject: [PATCH 12/14] Update home.ejs --- views/home.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/home.ejs b/views/home.ejs index c23582e..8827790 100644 --- a/views/home.ejs +++ b/views/home.ejs @@ -1 +1 @@ -

Heyyo :)

+

Hey Devops Team :)

From 18ac81df5136bae2ab99febf78858a5523949399 Mon Sep 17 00:00:00 2001 From: Afaqy Date: Thu, 25 Jul 2024 19:48:51 +0300 Subject: [PATCH 13/14] add playbook --- playbook.yaml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 playbook.yaml diff --git a/playbook.yaml b/playbook.yaml new file mode 100644 index 0000000..8e51ad8 --- /dev/null +++ b/playbook.yaml @@ -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 + From 23d5bd466595dafffb78a6b3ec71e04ac159eeb7 Mon Sep 17 00:00:00 2001 From: Ahmed Nageh Date: Sat, 10 May 2025 16:07:50 +0300 Subject: [PATCH 14/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7185ed4..0024fe2 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ make sure you have running kubernetes cluster on cloud or on hosted locally (kin ## 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 +https://linkerd.io/2.15/tasks/linkerd-smi/#install-the-linkerd-smi-extension # Usage :