带有 React 应用程序的 pod 在 kubernetes 上失败,状态为 CrashLoopBackOff
pod with React app failing with with status CrashLoopBackOff on kubernetes
我是 kubernetes 的新手。我是 运行 我的 Docker 桌面虚拟机中的 kubernetes 集群。以下是版本
Docker 桌面社区:2.3.0.4(稳定)
引擎:19.03.12
库伯内特斯:1.16.5
我创建了一个简单的 React 应用程序。下面是 Docker 文件。
FROM node:13.12.0-alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package*.json ./
RUN npm install
# add app files
COPY . ./
# start app
CMD ["npm", "start"]
我构建了一个 docker 图像并 运行 它。它工作正常。我在下面添加了图片 deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
labels:
app: test-react-app
namespace: dev
spec:
replicas: 1
selector:
matchLabels:
app: test-react-app
template:
metadata:
labels:
app: test-react-app
spec:
containers:
- name: test-react
image: myrepo/test-react:v2
imagePullPolicy: Never
ports:
- containerPort: 80
---
kind: Service
apiVersion: v1
metadata:
name: test-service
namespace: dev
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
nodePort: 31000
selector:
app: test-react-app
pod 永远不会启动。以下是 describe.
中的事件
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled <unknown> default-scheduler Successfully assigned dev/test-deployment-7766949554-m2fbz to docker-desktop
Normal Pulled 8m38s (x5 over 10m) kubelet, docker-desktop Container image "myrepo/test-react:v2" already present on machine
Normal Created 8m38s (x5 over 10m) kubelet, docker-desktop Created container test-react
Normal Started 8m38s (x5 over 10m) kubelet, docker-desktop Started container test-react
Warning BackOff 26s (x44 over 10m) kubelet, docker-desktop Back-off restarting failed container
以下是来自容器的日志。看起来容器是 运行..
> react-cart@0.1.0 start /app
> react-scripts start
[34mℹ[39m [90m「wds」[39m: Project is running at http://10.1.0.33/
[34mℹ[39m [90m「wds」[39m: webpack output is served from
[34mℹ[39m [90m「wds」[39m: Content not from webpack is served from /app/public
[34mℹ[39m [90m「wds」[39m: 404s will fallback to /
Starting the development server...
成功了!!!
我将 React 应用程序构建到生产应用程序中,然后复制了 docker 文件。我遵循了这个 link https://dev.to/rieckpil/deploy-a-react-application-to-kubernetes-in-5-easy-steps-516j.
中给出的技术
我是 kubernetes 的新手。我是 运行 我的 Docker 桌面虚拟机中的 kubernetes 集群。以下是版本
Docker 桌面社区:2.3.0.4(稳定)
引擎:19.03.12
库伯内特斯:1.16.5
我创建了一个简单的 React 应用程序。下面是 Docker 文件。
FROM node:13.12.0-alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package*.json ./
RUN npm install
# add app files
COPY . ./
# start app
CMD ["npm", "start"]
我构建了一个 docker 图像并 运行 它。它工作正常。我在下面添加了图片 deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
labels:
app: test-react-app
namespace: dev
spec:
replicas: 1
selector:
matchLabels:
app: test-react-app
template:
metadata:
labels:
app: test-react-app
spec:
containers:
- name: test-react
image: myrepo/test-react:v2
imagePullPolicy: Never
ports:
- containerPort: 80
---
kind: Service
apiVersion: v1
metadata:
name: test-service
namespace: dev
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
nodePort: 31000
selector:
app: test-react-app
pod 永远不会启动。以下是 describe.
中的事件Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled <unknown> default-scheduler Successfully assigned dev/test-deployment-7766949554-m2fbz to docker-desktop
Normal Pulled 8m38s (x5 over 10m) kubelet, docker-desktop Container image "myrepo/test-react:v2" already present on machine
Normal Created 8m38s (x5 over 10m) kubelet, docker-desktop Created container test-react
Normal Started 8m38s (x5 over 10m) kubelet, docker-desktop Started container test-react
Warning BackOff 26s (x44 over 10m) kubelet, docker-desktop Back-off restarting failed container
以下是来自容器的日志。看起来容器是 运行..
> react-cart@0.1.0 start /app
> react-scripts start
[34mℹ[39m [90m「wds」[39m: Project is running at http://10.1.0.33/
[34mℹ[39m [90m「wds」[39m: webpack output is served from
[34mℹ[39m [90m「wds」[39m: Content not from webpack is served from /app/public
[34mℹ[39m [90m「wds」[39m: 404s will fallback to /
Starting the development server...
成功了!!!
我将 React 应用程序构建到生产应用程序中,然后复制了 docker 文件。我遵循了这个 link https://dev.to/rieckpil/deploy-a-react-application-to-kubernetes-in-5-easy-steps-516j.
中给出的技术