错误-创建服务时退后重新启动失败的容器

时间:2019-01-01 23:04:33

标签: node.js docker kubernetes

如标题所述,我遇到错误

  

创建服务时退避重新启动失败的容器

我已经看到有关堆栈溢出的问题,但是我仍然不确定如何解决它。

这是我的部署yaml文件

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: book-api
spec:
  replicas: 1
  revisionHistoryLimit: 10
  template:
    metadata:
      name: book-api
      labels:
        app: book-api
    spec:
      containers:
      - name: book-api
        image: newmaster/kubecourse-books:v1
        ports:
        - name: http
          containerPort: 3000

服务部署文件为:

kind: Service
apiVersion: v1
metadata:
  name: exampleservice
spec:
  selector:
    app: myapp
  ports:
    - protocol: "TCP"
      # Port accessible inside cluster
      port: 8081
      # Port to forward to inside the pod
      targetPort: 8080
      # Port accessible outside cluster
      nodePort: 30000
  type: LoadBalancer

这是我的Dockerfile:

FROM node:alpine

# Create app directory
WORKDIR /src

# Install app dependencies
COPY package.json /src/
COPY package-lock.json /src/

RUN npm install

# Bundle app source
ADD . /src

RUN npm run build

EXPOSE 3000

CMD [ "npm", "run serve" ]

我不知道如何解决这个问题,我是Kubernetes和DevOps世界的新手。 回购在这里:https://github.com/codemasternode/BookService.Kubecourse.git

1 个答案:

答案 0 :(得分:1)

我尝试在本地运行您的部署,这是显示的日志:

kubectl log book-api-8d98bf6d5-zbv4q

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /root/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.5.0-next.0 /usr/local/lib/node_modules/npm

默认情况下,似乎没有命令在newmaster / kubecourse-books:v1上运行

我想如果您想运行默认的npm命令,则可以运行以下部署配置(请注意command值):

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: book-api
spec:
  replicas: 1
  revisionHistoryLimit: 10
  template:
    metadata:
      name: book-api
      labels:
        app: book-api
    spec:
      containers:
      - name: book-api
        image: newmaster/kubecourse-books:v1
        command: ["npm", "start"]
        ports:
        - name: http
          containerPort: 3000