This post was first published in Digital Ocean blog post.
You may have heard the buzz around Kubernetes and noticed that many companies have been rapidly adopting it. Due to its many components and vast ecosystem it can be quite confusing to find where the path starts to learn it.
In this session, you will learn the basics of containers and Kubernetes. Step by step, we will go through the entire process of packaging a Node.js application into a Docker container image and then deploying it on Kubernetes. We will demonstrate scaling to multiple replicas for better performance. The end result will be a resilient and scalable Node.js deployment.
You will leave this session with sufficient knowledge of containerization, Kubernetes basics, and the ability to deploy highly available, performant, and scalable Node.js applications on Kubernetes.
View the slides for this talk
Be sure to follow along with the recording for an explanation and replace kamaln7
with your own DockerHub username.
const express = require('express')
const os = require('os')
const app = express()
app.get('/', (req, res) => {
res.send(`Hi from ${os.hostname()}!`)
})
const port = 3000
app.listen(port, () => console.log(`listening on port ${port}`))
FROM node:13-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install --production
COPY . .
EXPOSE 3000
CMD node index.js
docker build -t kamaln7/node-hello-app .
index.js
and replace the word Hi
with Hello
.docker build -t kamaln7/node-hello-app .
docker run --rm -d -p 3000:3000 kamaln7/node-hello-app
docker ps
docker stop CONTAINER_ID
docker push kamaln7/node-hello-app
kubectl get nodes
kubectl create deployment --image kamaln7/node-hello-app node-app
kubectl scale deployment node-app --replicas 3
kubectl expose deployment node-app --port 3000
kubectl get services
kubectl get nodes -o wide
IP:port
to test the servicekubectl edit service node-app
port: 3000
with port: 80
type: NodePort
with type: LoadBalancer
kubectl get service