0

就此而言,我是 Kubernetes(和 Docker)的新手。我需要了解使用 Devspace 迁移现有 Vue.js 应用程序的过程。我的应用程序正在运行,有点像,但我没有连接到

ws://localhost:4000/graphql

或者能够建立一个mongo连接。

MongoServerSelectionError:连接 ECONNREFUSED 127.0.0.1:27017

相关的预先存在的 package.json 入口点

"serve": "vue-cli-service serve -mode development",
"build": "vue-cli-service build",
"apollo": "vue-cli-service apollo:dev --generate-schema",
"apollo:schema:generate": "vue-cli-service apollo:schema:generate",
"apollo:schema:publish": "vue-cli-service apollo:schema:publish",
"apollo:start": "vue-cli-service apollo:start",

应用结构

/apollo-server
  context.js  ## Mongo connection made here.
/src
  vue-apollo.js ## Apollo setup (Graphql is setup here.)
Dockerfile
devspace.yaml
package.json

现在,

Dockerfile

FROM node:13.12.0-alpine

# Set working directory
WORKDIR /app

# Add package.json to WORKDIR and install dependencies
COPY package*.json ./
RUN npm install

# Add source code files to WORKDIR
COPY . .

# Application port (optional)
# express server runs on port 3000
EXPOSE 3000

# Debugging port (optional)
# For remote debugging, add this port to devspace.yaml: dev.ports[*].forward[*].port: 9229
EXPOSE 9229

CMD ["npm", "start"]

开发空间.yaml

version: v1beta9
images:
  app:
    image: sandbox/practiceapp
    preferSyncOverRebuild: true
    injectRestartHelper: false
    cmd: ["yarn", "serve"]
    appendDockerfileInstructions:
    - USER root
  backend:
    image: sandbox/backend
    preferSyncOverRebuild: true
    injectRestartHelper: false
    entrypoint: ["yarn", "apollo"]
    appendDockerfileInstructions:
    - USER root
deployments:
- name: frontend
  helm:
    componentChart: true
    values:
      containers:
      - image: sandbox/practiceapp
      service:
        ports:
        - port: 8080
- name: backend
  helm:
    componentChart: true
    values:
      containers:
      - image: sandbox/backend
      service:
        ports:
        - port: 4000
        - port: 3000
        - port: 27017
# - name: mongo
#   helm:
#     componentChart: true
#     values:
#       containers:
#       - image: sandbox/mongo
#       service:
#         ports:
#         - port: 27017
dev:
  ports:
  - imageName: app
    forward:
    - port: 8080
  # - imageName: apollo
  #   forward:
  #     port: 3000
  # - imageName: graphql
  #   forward:
  #     port: 4000
  # - imageName: mongo
  #   forward:
  #     port: 27017
  open:
  - url: http://localhost:8080
  - url: http://localhost:4000/graphql
  sync:
  - imageName: app
    excludePaths:
    - .git/
    uploadExcludePaths:
    - Dockerfile
    - node_modules/*
    - '!node_modules/.temp/'
    - devspace.yaml
    onUpload:
      restartContainer: true
profiles:
- name: production
  patches:
  - op: remove
    path: images.app.injectRestartHelper
  - op: remove
    path: images.app.appendDockerfileInstructions
- name: interactive
  patches:
  - op: add
    path: dev.interactive
    value:
      defaultEnabled: true
  - op: add
    path: images.app.entrypoint
    value:
    - sleep
    - "9999999999"

我一直在寻找有关如何包含来自预先存在的应用程序的服务的信息,但我很难理解。我需要一些关于如何设置或在哪里查看的指导。

感谢您的帮助和时间。

4

2 回答 2

0

根据您提供的信息,我认为这可能是网络问题。请检查您的应用程序是否正在侦听所有接口而不是localhost仅侦听,因为这会导致连接被拒绝,如本故障排除指南中所述:https ://devspace.sh/cli/docs/guides/networking-domains#troubleshooting

于 2020-11-23T22:20:21.727 回答
0

对此的答案是重构我的应用程序的结构,并将服务端口deployments和转发端口包括在dev.ports.

deployments:
- name: app
  helm:
    componentChart: true
    values:
      containers:
      - image: namespace/frontend
      service:
        name: app-service
        ports:
        - port: 8080
        - port: 4000
dev:
   ports:
   - imageName: app
     forward:
     - port: 8080
     - port: 4000

我的应用程序的最终结构:

./backend
   .dockerignore
   Dockerfile
   package.json
./frontend
   .dockerignore
   Dockerfile
   package.json
devspace.yaml

至于连接 mongodb,我最初是从 minikube 开始,然后移至 docker-desktop,但由于在 docker-desktop 上使用了副本集,因此无法设置具有外部负载平衡访问权限的无头端口(localhost 不能作为外部分配两次) ip)。我将 bitnami 的 mongodb helm chart 与 devspace 一起使用。

于 2020-11-27T09:02:41.113 回答