NodeJS with Scaffold: How to set up dev environment?

11/10/2020

I'm trying to set up a dev environment for my Nodejs project using Skaffold to handle k8s. I notice that sometime when there's an error (usually syntax error cause I'm using auto-save), the entire local server seem to stop working and the error message doesn't get displayed. Sometimes it can fix itself but most of the time I have to restart skaffold. I have no idea what's causing the issues since the error message can be different everytime: "unable to connect to pod ..." , "502 error", "skipping deploy due to sync error" ...

Here's my simple dockerfile for node:

FROM node:alpine

WORKDIR /app

COPY package.json .
RUN npm install
COPY . .

CMD ["npm", "start"]

Package.json

{
  "name": "auth",
  "version": "1.0.0",
  "description": "Authorization Service for Ticketting",
  "main": "index.js",
  "scripts": {
    "start": "ts-node-dev src/index.ts"
  },
  "author": "Nam Nguyen",
  "license": "ISC",
  "devDependencies": {
    "ts-node-dev": "^1.0.0",
    "typescript": "^4.0.5"
  },
  "dependencies": {
    "@types/express": "^4.17.8",
    "express": "^4.17.1",
    "express-validator": "^6.6.1"
  }
}

Deployment yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 3
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: namng191/auth
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  type: ClusterIP
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3000
      targetPort: 3000

Ingress config yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
  rules:
    - host: ticketting.dev
      http:
        paths:
          - path: /api/users/?(.*)
            pathType: Prefix
            backend:
              service:
                name: auth-srv
                port:
                  number: 3000

Skaffold yaml

apiVersion: skaffold/v2beta9
kind: Config
deploy:
  kubectl:
    manifests:
      - ./infra/k8s/*
build:
  local:
    push: false
  artifacts:
    - image: namng191/auth
      context: ./auth
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
-- Nam
docker
kubernetes
nginx-ingress
node.js
skaffold

0 Answers