在GKE上部署Express API的错误

时间:2018-05-02 11:12:34

标签: node.js docker kubernetes google-kubernetes-engine

我有一个简单的快递应用程序,我试图在GKE上部署。

当我在本地构建和运行时,一切都按预期运行。

但是当我在GKE上通过kubectl进行部署时,我得到了..

sh: 1: babel: not found
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! express-api@1.0.0 prestart: `npm run -s build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the express-api@1.0.0 prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

我的部署yaml文件如下..

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: express-api
spec:
    replicas: 2
    minReadySeconds: 15
    strategy:
        rollingUpdate:
            maxSurge: 1
            maxUnavailable: 0
        type: RollingUpdate
    template:
      metadata:
        labels:
            app: express-api
            deployment: express-api-deployment
      spec:
        containers:
        - name: express-api
          image: pggriff/express-api:0.0.0-dev102
          imagePullPolicy: Always
          ports:
            - containerPort: 3000
              protocol: TCP
          readinessProbe:
            httpGet:
                path: /meta
                port: 3000
            periodSeconds: 1
            timeoutSeconds: 1
            successThreshold: 1
            failureThreshold: 10
---
apiVersion: v1
kind: Service
metadata:
  name: express-svc
spec:
  type: NodePort
  selector:
    app: express-api
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000

我的Dockerfile看起来像..

FROM node:carbon
RUN npm install -g pm2
WORKDIR /usr/src/app
COPY package*.json ./

ARG TARGET_ENV
COPY .env.$TARGET_ENV .env

COPY . .
EXPOSE 8080
CMD [ "npm", "start"]

我的Package.json有以下脚本..

  "scripts": {
    "test": "cross-env NODE_ENV=test nodemon --exec mocha ./**/*.spec.js --compilers js:babel-core/register",
    "dev": "cross-env NODE_ENV=dev nodemon -w src --exec \"babel-node src --presets env,stage-0\"",
    "build": "babel src -s -D -d dist --presets env,stage-0",
    "start": "cross-env NODE_ENV=production pm2-runtime dist",
    "prestart": "npm run -s build",
    "clean": "rimraf dist/",
    "build:dev": "bash scripts/build-dev.sh",
    "deploy:dev": "bash scripts/deploy-dev.sh"
  },

我有以下依赖...

  "dependencies": {
    "babel": "^6.23.0",
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-0": "^6.24.1",
    "body-parser": "^1.18.2",
    "cors": "^2.8.4",
    "cross-env": "^5.1.4",
    "dotenv": "^5.0.1",
    "express": "^4.16.3",
    "helmet": "^3.12.0"
  },
  "devDependencies": {
    "chai": "^4.1.2",
    "mocha": "^5.1.1",
    "morgan": "^1.9.0",
    "nodemon": "^1.17.3",
    "rimraf": "^2.6.2",
    "supertest": "^3.0.0"
  }

我还设置了一个bash脚本来处理deploy for,看起来像......

if [ -z "$1" ]; then
  echo "Missing version / tag"
  exit
fi

echo "Deploying $1"
docker build --build-arg TARGET_ENV=dev -t pggriff/express-api:$1 . &&
gcloud config set project foo-project &&
gcloud container clusters get-credentials dev-cluster --zone europe-west4-a &&
gcloud docker -- push pggriff/express-api:$1 &&
kubectl apply -f deployment.dev.yaml

1 个答案:

答案 0 :(得分:0)

我不小心从我的docker文件中删除了npm install命令