[英]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:主要问题如下:
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 秒。Starting the development server...
for another two minutes.Starting the development server...
再等两分钟。 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 中启动。
Syncing 1 files for <image>... Watching for changes...
, but nothing changes even after a refresh. Syncing 1 files for <image>... Watching for changes...
,但即使刷新后也没有任何变化。 What I've tried我试过的
create-react-app
application.create-react-app
应用程序。 The behavior is the same regardless.minikube delete
and minikube start
several times (did this because even the server deployment started acting erratically after trying create-react-app
) minikube delete
和minikube 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.我将不得不跳过所有这些的安装过程,因为它相当长,所以以下步骤假设您已经设置了这个。
Make a project directory:创建一个项目目录:
mkdir project
Make a Kubernetes manifest directory and move into it:创建一个 Kubernetes 清单目录并进入它:
mkdir k8s && cd k8s
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
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
Move back into the parent:移回父级:
cd..
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
Start a new create-react-app
project:启动一个新的
create-react-app
项目:
npx create-react-app test-app
Change into the directory:切换到目录:
cd test-app
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. .
Create a .dockerignore
file and add the following:创建一个
.dockerignore
文件并添加以下内容:
node_modules *.swp
Go back into the parent directory: Go 回到父目录:
cd..
Make sure minikube
is running:确保
minikube
正在运行:
minikube start
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.