简体   繁体   English

create-react-app 和 Skaffold kubernetes 行为不稳定且缓慢

[英]Erratic and slow behavior with create-react-app and Skaffold kubernetes

I have Skaffold working well with local development server and database deployments.我让 Skaffold 与本地开发服务器和数据库部署配合得很好。 I'm trying to get working on the create-react-app front-end, but the behavior is incredibly slow and erratic.我正在尝试create-react-app前端,但这种行为非常缓慢且不稳定。

Issues问题

The main problems are the following:主要问题如下:

  1. It takes upwards of five minutes from running skaffold dev --port-forward --tail for it finally start spinning up.运行skaffold dev --port-forward --tail需要五分钟以上,它最终开始旋转。 Running just a docker build takes less than 30 seconds.仅运行docker build只需不到 30 秒。
  2. When it finally starts spinning up, it just sits on Starting the development server... for another two minutes.当它最终开始旋转时,它只是在Starting the development server...再等两分钟。
  3. Then, nine times out of ten, I get the following errors after several minutes (there are three because that is how many replicas there are):然后,十分之九,几分钟后我得到以下错误(有三个,因为那是有多少副本): 在此处输入图像描述

    One out of ten times, it will actually go into the Compiled Successfully. You can now view in the browser.十分之一的时候,它实际上会 go 进入Compiled Successfully. You can now view in the browser. Compiled Successfully. You can now view in the browser. It never does launch in Chrome though.但它永远不会在 Chrome 中启动。

  4. Changes to JS in create-react-app are never reflected in new browser. create-react-app 中对 JS 的更改永远不会反映在新浏览器中。 You have to stop and run Skaffold again.您必须停止并再次运行 Skaffold。 Skaffold does say Syncing 1 files for <image>... Watching for changes... , but nothing changes even after a refresh. Skaffold 确实说 Syncing Syncing 1 files for <image>... Watching for changes... ,但即使刷新后也没有任何变化。

What I've tried我试过的

  1. I've really simplified what I'm trying to do to make it easier to sort this out, so I'm using just an OOTB create-react-app application.我真的简化了我正在尝试做的事情,以便更容易解决这个问题,所以我只使用了一个 OOTB create-react-app应用程序。 The behavior is the same regardless.无论如何,行为都是相同的。
  2. minikube delete and minikube start several times (did this because even the server deployment started acting erratically after trying create-react-app ) minikube deleteminikube start几次(这样做是因为即使服务器部署在尝试create-react-app后也开始出现异常行为)

Code and Steps to Reproduce重现的代码和步骤

I'm on macOS Mojave (10.14.6) using Docker for Mac, Kubernetes (v1.16.0), minikube (v1.4.0), Skaffold (v0.39.0), and create-react-app .我在 macOS Mojave (10.14.6) 上使用 Docker for Mac、Kubernetes (v1.16.0)、minikube (v1.4.0)、Skaffold (v0.39.0) 和create-react-app I'll have to skip the installation process for all of these since it is fairly lengthy, so the following steps assume you have this already setup.我将不得不跳过所有这些的安装过程,因为它相当长,所以以下步骤假设您已经设置了这个。

  1. Make a project directory:创建一个项目目录:

    mkdir project

  2. Make a Kubernetes manifest directory and move into it:创建一个 Kubernetes 清单目录并进入它:

    mkdir k8s && cd k8s

  3. Make a client-deployment.yaml and add the following:制作一个client-deployment.yaml并添加以下内容:

     apiVersion: apps/v1 kind: Deployment metadata: name: client-deployment spec: replicas: 3 selector: matchLabels: component: web template: metadata: labels: component: web spec: containers: - name: client image: testapp/client ports: - containerPort: 3000
  4. Make a client-cluster-ip-service.yaml and add the following:制作一个client-cluster-ip-service.yaml并添加以下内容:

     apiVersion: v1 kind: Service metadata: name: client-cluster-ip-service spec: type: ClusterIP selector: component: web ports: - port: 3000 targetPort: 3000
  5. Move back into the parent:移回父级:

    cd..

  6. Create a skaffold.yaml and add the following:创建一个skaffold.yaml并添加以下内容:

     apiVersion: skaffold/v1beta15 kind: Config build: local: push: false artifacts: - image: testapp/client context: web docker: dockerfile: Dockerfile.dev sync: manual: - src: "**/*.js" dest: . - src: "**/*.html" dest: . - src: "**/*.css" dest: . deploy: kubectl: manifests: - k8s/client-deployment.yaml - k8s/client-cluster-ip-service.yaml portForward: - resourceType: service resourceName: client-cluster-ip-service port: 3000 localPort: 3000
  7. Start a new create-react-app project:启动一个新的create-react-app项目:

    npx create-react-app test-app

  8. Change into the directory:切换到目录:

    cd test-app

  9. Create a Dockerfile.dev and add the following:创建Dockerfile.dev并添加以下内容:

     FROM node:alpine WORKDIR '/app' EXPOSE 3000 CMD ["npm", "run", "start"] COPY package*./ RUN npm install COPY. .
  10. Create a .dockerignore file and add the following:创建一个.dockerignore文件并添加以下内容:

     node_modules *.swp
  11. Go back into the parent directory: Go 回到父目录:

    cd..

  12. Make sure minikube is running:确保minikube正在运行:

    minikube start

  13. Run the skaffold.yaml :运行skaffold.yaml

    skaffold dev --port-forward --tail

This is what produces the issues for me.这就是给我带来问题的原因。

Ok.好的。 Disregard.漠视。 Started with one replica and it worked fine.从一个副本开始,它运行良好。 Two worked fine.两个工作得很好。 Three worked if skaffold was already running, but not from a fresh skaffold dev --port-forward --tail .如果skaffold已经在运行,则三个工作,但不是来自新的skaffold dev --port-forward --tail

skaffold ssh and then did a top . skaffold ssh然后做了一个top Was running out of RAM... well was at 86% utilization.内存用完了……利用率为 86%。 Increased it from the default 2GB to 8GB and now it works fine.将其从默认的 2GB 增加到 8GB,现在它可以正常工作了。

First deleted the VM with minikube delete and then created a new one with minikube start --memory='8g' .首先使用minikube delete删除虚拟机,然后使用minikube start --memory='8g'创建一个新虚拟机。 All good now.现在一切都好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM