This is just a todo-list for me. It might not be completed, and of course is not production ready. You should have minikube and docker desktop installed.
First of all, create a basic fastify microservice running in typescript using this tutorial.
Let’s create our docker image
Create a Dockerfile
for your microservice like…
# node js slim image
FROM node:20-slim
# app folder
WORKDIR /usr/src/app
# copy dependencies files
COPY package*.json ./
RUN npm install
# copy the rest
COPY . .
## build
RUN npm run build:ts
# listening on port 3000
EXPOSE 3000
# run the app
CMD ["npm", "start"]
Start minikube and point it to your docker desktop installation
minikube start
eval $(minikube docker-env)
Let’s assume that my microservice is spitting out the current date… Let’s create the docker image for it.
docker build -t date-service:latest .
We now need the deployment and service yaml files for it
apiVersion: apps/v1
kind: Deployment
metadata:
name: date-deployment
spec:
replicas: 2
selector:
matchLabels:
app: date-app
template:
metadata:
labels:
app: date-app
spec:
containers:
- name: date-container
image: date-service:latest
imagePullPolicy: Never
ports:
- containerPort: 3000
apiVersion: v1
kind: Service
metadata:
name: date-service
spec:
type: ClusterIP
selector:
app: date-app
ports:
- protocol: TCP
port: 80
targetPort: 3000
Let’s create the ingress for our microservice in order to be exposed
apiVersion: v1
kind: Service
metadata:
name: date-service
spec:
type: ClusterIP
selector:
app: date-app
ports:
- protocol: TCP
port: 80
targetPort: 3000
Enable the Ingress Add-ons in Minikube
minikube addons enable ingress-dns
minikube addons enable ingress
Deploy everything and create the minikube tunnel
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml
minikube tunnel # (in a new terminal window)
Add entry to /etc/hosts
127.0.0.1 date-service.local
If you want to share a comment or report an issue with this post, please send me an email to napolux@gmail.com