Kubernetes 不运行镜像,但镜像在本地运行

时间:2021-06-07 00:46:36

标签: node.js express kubernetes

一直在拉我的头发。我有一个在本地运行良好的映像,但是当我尝试在我的 kubernetes 集群上运行它时,我收到以下消息。我不是在 kubernetes 上构建它。下面的日志是 kubectl log ... 命令后显示的内容,这意味着我的 dockerfile 中的 CMD 行在 kubernetes 集群中不起作用。

> chia-plot-manager-api@0.0.1 prestart /var/app
> npm run build
> chia-plot-manager-api@0.0.1 build /var/app
> rimraf build && tsc
> chia-plot-manager-api@0.0.1 start /var/app
> node build/index.js
internal/modules/cjs/loader.js:979
  throw err;
  ^
Error: Cannot find module '/var/app/build/index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15)
    at Function.Module._load (internal/modules/cjs/loader.js:859:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! chia-plot-manager-api@0.0.1 start: `node build/index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the chia-plot-manager-api@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-06-07T00_01_43_247Z-debug.log

可以通过运行 docker pull ghcr.io/128bitstudios/chia-plot-manager-api:latest

找到图像

如果你想在本地运行它,你可以输入 docker run -e PORT=3000 -e CHIA_LOGS=/chialogs -e NODE_ENV=local -e DEBUG=false -p 3000:3000 ghcr.io/128bitstudios/chia-plot-manager-api:latest

另外值得指出的是,我尝试了另一个快速回波图像进行测试,但也没有奏效。它被称为 alchen99/express-hello,我有几个 React 应用在其他部署中运行,并且构建/工作得非常好。

我认为这可能与内存有关,因为将 CPU 和 MEM 增加到现在的四倍,但它仍然失败。鉴于上面的错误^^^ 我认为这可能与图像有关?

我的 Kubernetes 配置是这样的...

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cpm-api
  namespace: apis
  labels:
    app: cpm-api
    version: latest
spec:
  selector:
    matchLabels:
      app: cpm-api
  strategy:
    type: Recreate
  template:
    metadata:
      name: cpm-api
      annotations:
        linkerd.io/inject: enabled
      labels:
        app: cpm-api
        version: latest
    spec:
      nodeSelector:
        beta.kubernetes.io/os: linux
        beta.kubernetes.io/arch: amd64
      containers:
        - name: cpm-api
          image: ghcr.io/128bitstudios/chia-plot-manager-api:latest
          imagePullPolicy: Always
          resources:
            requests:
              memory: 64Mi
              cpu: 10m
            limits:
              memory: 64Mi
              cpu: 10m
          readinessProbe:
            httpGet:
              path: /cpm-api
              port: 3000
          livenessProbe:
            httpGet:
              path: /cpm-api
              port: 3000
            periodSeconds: 30
          ports:
            - containerPort: 3000
          envFrom:
            - configMapRef:
                name: cpm-api
      imagePullSecrets:
        - name: ghcr-secret-apis

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: cpm-api
  namespace: apis
spec:
  selector:
    app: cpm-api
  ports:
    - name: http
      port: 5115
      targetPort: 3000
      protocol: TCP
  type: ClusterIP

configmap.yaml

apiVersion: v1
data:
  LOG_LEVEL: debug
  PORT: "3000"
  NODE_ENV: local
  DEBUG: "false"
  CHIA_LOGS: "/chialogs"
kind: ConfigMap
metadata:
  name: cpm-api
  namespace: apis

ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: apis
  namespace: apis
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  tls:
    - hosts:
        - apis.bradio.io
      secretName: apis-tls
  rules:
    - host: apis.bradio.io
      http:
        paths:
          - path: /cpm-api
            pathType: Prefix
            backend:
              service:
                name: cpm-api
                port:
                  number: 5115

感谢我提供的任何帮助,并在需要时提供更多信息。

0 个答案:

没有答案