【问题标题】:Docker image works, Kubernetes Pod not working. Ubuntu. Log: /bin/sh: [npm,start]: not foundDocker 镜像工作,Kubernetes Pod 不工作。 Ubuntu。日志:/bin/sh:[npm,start]:未找到
【发布时间】:2020-11-13 13:42:32
【问题描述】:

我正在学习一门使用 Kubernetes 的课程,当我尝试在 Kubernetes 中创建 pod 时遇到了错误。

我正在使用 Ubuntu、AMD64

我按照这些说明安装了 microk8s.kubectl (https://ubuntu.com/kubernetes/install)

这是我的 Dockerfile,当我只使用 Docker 时它可以正常运行。

FROM node:alpine

WORKDIR /app

COPY package.json ./
RUN npm install

COPY ./ ./

CMD ["npm", "start"]

这是我的 posts.yaml 文件,逐字记录我正在学习的课程

apiVersion: v1
kind: Pod
metadata:
  name: posts
spec:
  containers:
    - name: posts
      image: emendoza1986/blog_posts:0.0.1

kubectl 获取 pod 的输出

NAME    READY   STATUS             RESTARTS   AGE
posts   0/1     CrashLoopBackOff   6          10m

kubectl 日志帖子的输出

/bin/sh: [npm,start]: not found

kubectl describe pod 帖子的输出

Name:         posts
Namespace:    default
Priority:     0
Node:         desktope/192.168.0.18
Start Time:   Thu, 23 Jul 2020 10:58:40 -0700
Labels:       <none>
Annotations:  Status:  Running
IP:           10.1.87.20
IPs:
  IP:  10.1.87.20
Containers:
  posts:
    Container ID:   containerd://acb403c53759670370959cfa2cc0939f53126aee889e1f6dc2e831bc4dc22c3c
    Image:          emendoza1986/blog_posts:0.0.1
    Image ID:       docker.io/emendoza1986/blog_posts@sha256:f69b30cf0382d4c273643ac11c505378854b966063974cc57d187718cc0b0fd5
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    127
      Started:      Thu, 23 Jul 2020 10:58:59 -0700
      Finished:     Thu, 23 Jul 2020 10:58:59 -0700
    Ready:          False
    Restart Count:  2
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-2fm2c (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-2fm2c:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-2fm2c
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  48s                default-scheduler  Successfully assigned default/posts to desktope
  Normal   Pulled     29s (x3 over 47s)  kubelet, desktope  Container image "emendoza1986/blog_posts:0.0.1" already present on machine
  Normal   Created    29s (x3 over 47s)  kubelet, desktope  Created container posts
  Normal   Started    29s (x3 over 47s)  kubelet, desktope  Started container posts
  Warning  BackOff    12s (x4 over 45s)  kubelet, desktope  Back-off restarting failed container

microk8s.status

的输出
microk8s is running
addons:
dashboard: enabled
dns: enabled
metrics-server: enabled
cilium: disabled
fluentd: disabled
gpu: disabled
helm: disabled
helm3: disabled
host-access: disabled
ingress: disabled
istio: disabled
jaeger: disabled
knative: disabled
kubeflow: disabled
linkerd: disabled
metallb: disabled
prometheus: disabled
rbac: disabled
registry: disabled
storage: disabled

microk8s 检查的输出

Inspecting Certificates
Inspecting services
  Service snap.microk8s.daemon-cluster-agent is running
  Service snap.microk8s.daemon-containerd is running
  Service snap.microk8s.daemon-apiserver is running
  Service snap.microk8s.daemon-apiserver-kicker is running
  Service snap.microk8s.daemon-proxy is running
  Service snap.microk8s.daemon-kubelet is running
  Service snap.microk8s.daemon-scheduler is running
  Service snap.microk8s.daemon-controller-manager is running
  Service snap.microk8s.daemon-flanneld is running
  Service snap.microk8s.daemon-etcd is running
  Copy service arguments to the final report tarball
Inspecting AppArmor configuration
Gathering system information
  Copy processes list to the final report tarball
  Copy snap list to the final report tarball
  Copy VM name (or none) to the final report tarball
  Copy disk usage information to the final report tarball
  Copy memory usage information to the final report tarball
  Copy server uptime to the final report tarball
  Copy current linux distribution to the final report tarball
  Copy openSSL information to the final report tarball
  Copy network configuration to the final report tarball
Inspecting kubernetes cluster
  Inspect kubernetes cluster

Building the report tarball
  Report tarball is at /var/snap/microk8s/1503/inspection-report-20200723_112646.tar.gz

我看到来自日志的错误,但我无法找到解决方案。感谢您的帮助!

【问题讨论】:

  • 除非解析为 JSON,否则不会被视为列表
  • 行情很重要。需要["npm", "start"];错误消息暗示实际值不同。确保它使用真正的 ASCII 引号而不是卷曲的“智能”引号等。或者根本不要尝试将其作为 JSON 传递并切换到 CMD npm start
  • 我发布了我的 Dockerfile。它看起来正确吗?
  • 您已经发布了有效的示例。您的实际设置必须不同。你实际的 Dockerfile 和这里​​的那个,它们可能不同。
  • 确保拉取正确的图像。由于你没有使用latest标签,如果你已经将图片推送到同一个标签中,kubernetes默认不会拉取新的图片

标签: docker npm kubernetes kubectl microk8s


【解决方案1】:

感谢您提供帮助的 cmets。最初我的 Dockerfile 为 CMD ['npm', 'start']。 我已在本地修复它 CMD ["npm", "start"] 但我没有将新版本推送到 docker hub。 推送新版本解决了这个问题。

【讨论】:

    猜你喜欢
    • 2017-02-07
    • 2021-09-07
    • 2019-11-19
    • 2020-03-11
    • 2021-07-24
    • 2022-11-13
    • 2019-09-11
    • 2021-03-24
    • 2018-04-26
    相关资源
    最近更新 更多