The Node JS app that I'm trying to deploy in Kubernetes runs on express js
as a backend framework.The repository is managed via Bitbucket
. The application is a microservice and the pipeline manifest file for building the Docker image is written this way:
options:
docker: true
image: node:14.17.0
pipelines:
branches:
test:
- step:
services:
- docker
name: Build and push new docker image
deployment: dev
script:
- yarn install
- yarn build
- yarn test
- yarn lint
- make deploy.dev
- docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
- docker build -t testapp/helloapp:latest -f ./Dockerfile .
- docker push testapp/helloapp
caches:
- docker # adds docker layer caching
The K8s cluster is hosted on cloud but does not have the internal Load Balancer
of their own. The K8s cluster version is v1.22.4
and MetalLB v0.11.0
is configured to serve the Load Balancing purpose. To expose the K8s service
- Cloudflare Tunnel is configured as a K8s deployment
.
So, this is the manifest file set-up used for building the Docker image. The pipeline deploys successfully and in the Kubernetes part, this is the service
and deployment
manifest:
apiVersion: v1
kind: Service
metadata:
name: helloapp
labels:
app: helloapp
spec:
type: NodePort
ports:
- port: 5000
targetPort: 7000
protocol: TCP
name: https
selector:
app: helloapp
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloapp
labels:
app: helloapp
spec:
replicas: 3
selector:
matchLabels:
app: helloapp
template:
metadata:
labels:
app: helloapp
spec:
imagePullSecrets:
- name: regcred
containers:
- name: helloapp
image: testapp/helloapp:latest
Also, here is the Dockerfile
snippet to give more clarity on what I have been doing:
FROM node:14.17.0
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD node app.js
EXPOSE 8100
Just to give a context, the service and deployment works fine, with no CrashLoopBackOff
or any other errors.
My doubt here is, there is dist
directory which is not getting deployed to Docker Hub as it is generated during npm build
. How can I deploy the app along with the dist
directory without having to worry about security risks? Any feedbacks and suggestions on where I could add a script to pull the dist
directory would be appreciated.