2

我正在尝试使用 Skaffold 为我的 Nodejs 项目设置开发环境来处理 k8s。我注意到有时出现错误(通常是语法错误导致我使用自动保存),整个本地服务器似乎停止工作并且没有显示错误消息。有时它可以自行修复,但大多数时候我必须重新启动 skaffold。我不知道是什么导致了问题,因为错误消息每次都可能不同:“无法连接到 pod ...”、“502 错误”、“由于同步错误而跳过部署”...

这是我用于节点的简单 dockerfile:

FROM node:alpine

WORKDIR /app

COPY package.json .
RUN npm install
COPY . .

CMD ["npm", "start"]

包.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"
  }
}

部署 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

入口配置 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

脚手架 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: .
4

0 回答 0