The document discusses various techniques for creating cloud native Node.js applications including:
- Using Docker to containerize a Node.js application including installing dependencies and copying the application into a slim Node.js image to reduce size.
- Deploying the containerized application to Kubernetes using Helm charts which provide templates for Kubernetes resources like deployments, services, and Istio configuration.
- The Helm chart files define properties that can be customized like the Docker image, resource requests, liveness probes, and replica counts.
27. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
# Change working directory
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Copy package.json and package-lock.json
COPY package*.json /app/
# Install app dependencies
RUN npm install —-production
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
CMD ["npm", "start"]
28. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
# Change working directory
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Copy package.json and package-lock.json
COPY package*.json /app/
# Install app dependencies
RUN npm install —-production
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
CMD ["npm", "start"]
Node.js 8 Docker Image
29. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
# Change working directory
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Copy package.json and package-lock.json
COPY package*.json /app/
# Install app dependencies
RUN npm install —-production
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
CMD ["npm", "start"]
Node.js 8 Docker Image
Operating System Updates
30. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
# Change working directory
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Copy package.json and package-lock.json
COPY package*.json /app/
# Install app dependencies
RUN npm install —-production
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
CMD ["npm", "start"]
Node.js 8 Docker Image
Operating System Updates
package.json
31. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
# Change working directory
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Copy package.json and package-lock.json
COPY package*.json /app/
# Install app dependencies
RUN npm install —-production
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
CMD ["npm", "start"]
Node.js 8 Docker Image
Operating System Updates
package.json
node_modules
32. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
# Change working directory
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Copy package.json and package-lock.json
COPY package*.json /app/
# Install app dependencies
RUN npm install —-production
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
CMD ["npm", "start"]
Node.js 8 Docker Image
Operating System Updates
package.json
node_modules
Application
33. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
# Change working directory
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Copy package.json and package-lock.json
COPY package*.json /app/
# Install app dependencies
RUN npm install —-production
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
CMD ["npm", "start"]
Node.js 8 Docker Image
Operating System Updates
package.json
node_modules
Application
716 MB
34. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY package*.json /app/
RUN npm install —-production
Node.js 8 Docker Image
Operating System Updates
package.json
node_modules
716 MB
35. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY package*.json /app/
RUN npm install —-production
# Copy the dependencies into a Slim Node docker image
FROM node:8-slim
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY --from=0 /app/node_modules /app/node_modules
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
EXPOSE 3000
CMD ["npm", "start"]
Node.js 8 Docker Image
Operating System Updates
package.json
node_modules
716 MB
36. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY package.json /app/
RUN npm install —production
# Copy the dependencies into a Slim Node docker image
FROM node:8-slim
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY --from=0 /app/node_modules /app/node_modules
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
EXPOSE 3000
CMD ["npm", "start"]
node_modules
716 MB
37. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY package.json /app/
RUN npm install —production
# Copy the dependencies into a Slim Node docker image
FROM node:8-slim
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY --from=0 /app/node_modules /app/node_modules
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
EXPOSE 3000
CMD ["npm", "start"]
node_modules
716 MB
Node.js 8 SLIM Docker Image
38. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY package.json /app/
RUN npm install —production
# Copy the dependencies into a Slim Node docker image
FROM node:8-slim
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY --from=0 /app/node_modules /app/node_modules
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
EXPOSE 3000
CMD ["npm", "start"]
node_modules
716 MB
Node.js 8 SLIM Docker Image
Operating System Updates
39. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY package.json /app/
RUN npm install —production
# Copy the dependencies into a Slim Node docker image
FROM node:8-slim
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY --from=0 /app/node_modules /app/node_modules
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
EXPOSE 3000
CMD ["npm", "start"]
node_modules
716 MB
Node.js 8 SLIM Docker Image
Operating System Updates
package.json
Application
40. 229 MB
func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
FROM node:8
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY package.json /app/
RUN npm install —production
# Copy the dependencies into a Slim Node docker image
FROM node:8-slim
WORKDIR "/app"
# Install OS updates
RUN apt-get update && apt-get dist-upgrade -y && apt-get clean
&& echo 'Finished installing dependencies'
# Install app dependencies
COPY --from=0 /app/node_modules /app/node_modules
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
USER node
EXPOSE 3000
CMD ["npm", "start"]
node_modules
Node.js 8 SLIM Docker Image
Operating System Updates
package.json
Application
45. HELM CHARTS
func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
/chart/nodeserver/templates/basedeployment.yaml
/chart/nodeserver/templates/deployment.yaml
/chart/nodeserver/templates/service.yaml
/chart/nodeserver/templates/hpa.yaml
/chart/nodeserver/templates/istio.yaml
/chart/nodeserver/Chart.yaml
/chart/nodeserver/values.yaml
apiVersion: v1
description: A Helm chart for Kubernetes
name: nodeserver
version: 1.0.0
46. HELM CHARTS
func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
/chart/nodeserver/templates/basedeployment.yaml
/chart/nodeserver/templates/deployment.yaml
/chart/nodeserver/templates/service.yaml
/chart/nodeserver/templates/hpa.yaml
/chart/nodeserver/templates/istio.yaml
/chart/nodeserver/Chart.yaml
/chart/nodeserver/values.yaml
apiVersion: v1
description: A Helm chart for Kubernetes
name: nodeserver
version: 1.0.0
66. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
const health = require(‘@cloudnative/health-connect');
let healthcheck = new health.HealthChecker();
const readyPromise = new Promise(function (resolve, _reject) {
resolve();
});
let readyCheck = new health.ReadinessCheck("ready", readyPromise);
const livePromise = new Promise(function (resolve, _reject) {
resolve();
});
let liveCheck = new health.LivenessCheck("live", livePromise);
const shutdownPromise = new Promise(function (resolve, _reject) {
resolve();
});
let shutdownCheck = new health.ShutdownCheck(“shut”, shutdownProm);
healthcheck.registerReadinessCheck(readyCheck);
healthcheck.registerLivenessCheck(liveCheck);
healthcheck.registerShutdownCheck(shutdownCheck);
app.use('/ready', health.ReadinessEndpoint(healthcheck))
app.use('/health', health.LivenessEndpoint(healthcheck))
-
Health Checks
78. func add(_ a: Int, to b: Int)
-> Void {
print(a + b)
}
let a = ”5”
let b = 3
add(a, to: b)
const prometheus = require(‘appmetrics-prometheus’).attach();-
Introduction- We’re going to be talking about Cloud Native Node.js, and how that relates to the CloudNativeJS project.- Cloud-native applications are applications that are specifically designed to leverage cloud technologies. - Background, why Node.js is so popular for building Microservices and Cloud Native applications
Few performance characteristics that are important when building microservices or applications for the cloud - First is IO speed
Often building Microservices that are REST API parsing responses
Higher the number, the more it can process
1150 what per second?
- Startup Speed
This is important for initial deploy, but also for scaling, if you want to spin up new or multiple instances based on the workload
Node.js with Express has a subsecond startup before it can handle requests
Whereas Spring boot is 14 seconds before it can handle requests
These