尝试在kubernetes上运行ui(app)时出错?

时间:2019-06-17 16:15:13

标签: node.js docker npm kubernetes

基本上,当我尝试使用kubectl在kubernetess上运行我的应用程序(UI)时,广告连播失败并显示错误。

吊舱日志


> wootz@0.1.0 start /usr/src/app
> node scripts/start.js

internal/modules/cjs/loader.js:626
    throw err;
    ^

Error: Cannot find module 'react-dev-utils/chalk'
Require stack:
- /usr/src/app/scripts/start.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.Module._load (internal/modules/cjs/loader.js:527:27)
    at Module.require (internal/modules/cjs/loader.js:681:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/usr/src/app/scripts/start.js:19:15)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/src/app/scripts/start.js' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wootz@0.1.0 start: `node scripts/start.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the wootz@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log                                                                                                                                                             ging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-06-17T15_56_02_649Z-debug.log

uipersistantvolume

kind: PersistentVolume
apiVersion: v1
metadata:
  name: ui-initdb-pv-volume
  labels:
    type: local
    app: ui
spec:
  storageClassName: manual
  capacity:
    storage: 1Mi
  accessModes:
    - ReadOnlyMany
  hostPath:
    path: "/home/vignesh/pagedesigneryamls/client"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: ui-initdb-pv-claim-one
  labels:
    app: ui
spec:
  storageClassName: manual
  accessModes:
    - ReadOnlyMany
  resources:
    requests:
      storage: 1Mi

uipersistantvolumetwo

kind: PersistentVolume
apiVersion: v1
metadata:
  name: ui-initdb-pv-volume-two
  labels:
    type: local
    app: ui
spec:
  storageClassName: manual
  capacity:
    storage: 1Mi
  accessModes:
    - ReadOnlyMany
  hostPath:
    path: "/home/vignesh/pagedesigneryamls/client"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: ui-initdb-pv-claim-two
  labels:
    app: ui
spec:
  storageClassName: manual
  accessModes:
    - ReadOnlyMany
  resources:
    requests:
      storage: 1Mi

ui.yaml

apiVersion: v1
kind: Service
metadata:
  name: ui
  labels:
    app: ui
spec:

  ports:
  - name: myport
    port: 80
    targetPort: 3000

  selector:
    app: ui
    tier: frontend

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ui
  labels:
    app: ui
spec:
  selector:
    matchLabels:
      app: ui
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: ui
        tier: frontend
    spec:

      containers:
      - image: suji165475/devops-sample:updatedclientdockerfile
        name: ui
        ports:
        - containerPort: 80
          name: myport
        volumeMounts:
        - name: ui-persistent-storage-one
          mountPath: /usr/src/app
        - name: ui-persistent-storage-two
          mountPath: /usr/src/app/node_modules
      volumes:
      - name: ui-persistent-storage-one
        persistentVolumeClaim:
          claimName: ui-initdb-pv-claim-one
      - name: ui-persistent-storage-two
        persistentVolumeClaim:
          claimName: ui-initdb-pv-claim-two

ui yaml中使用的图像是使用以下dockerfile构建的


FROM node:12.4.0-alpine
RUN mkdir -p usr/src/app
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install && npm cache clean --force
RUN npm install -g webpack-cli
WORKDIR /usr/src/app
COPY . .
WORKDIR /usr/src/app
EXPOSE 3000
RUN npm run build
CMD [ "npm","start" ]

我该如何解决错误找不到模块'react-dev-utils / chalk'? dockerfile中缺少任何内容吗?

1 个答案:

答案 0 :(得分:0)

删除所有卷,永久卷和永久卷声明。您的代码在您的映像中(您可以COPY . .插入它),并且应该从那里运行它。

Kubernetes非常不适合用作实时开发环境。请注意,您在尝试将本地源代码注入容器中所花费的YAML空间比部署中的其他所有项目都多。在实际的生产设置中,您还必须确保源代码可以连接到每个节点(并假设您甚至可以访问这些节点;在许多云托管环境中则不会)。

我建议您正常开发您的应用程序-不使用Docker,不使用Kubernetes-仅在其运行后,才需要打包和部署它。在Kubernetes中滚动零停机时间重启等操作与开发环境中的实时代码重新加载完全不同。