
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-appdocker psdocker stop CONTAINER_IDdocker push kamaln7/node-hello-appkubectl get nodeskubectl create deployment --image kamaln7/node-hello-app node-appkubectl scale deployment node-app --replicas 3kubectl expose deployment node-app --port 3000kubectl get serviceskubectl get nodes -o wideIP:port to test the servicekubectl edit service node-appport: 3000 with port: 80type: NodePort with type: LoadBalancerkubectl get service