kubernetes pod(mssql-tools)出现故障,出现CrashLoopBackOff错误,正在重新启动

pnwntuvh  于 2022-12-29  发布在  Kubernetes
关注(0)|答案(2)|浏览(184)

我在Windows 11中的WSL 2中使用Rancher Dekstop作为K8。我尝试使用简单的yaml创建一个pod:

apiVersion: v1
kind: Pod
metadata:
  name: mssql-tools
  labels:
    name: mssql-tools
spec:
  containers:
  - name: mssql-tools
    image: mcr.microsoft.com/mssql-tools:latest

但它不断地给出CrashLoopBackOff误差。

$ kubectl get pods
NAME          READY   STATUS             RESTARTS      AGE
mssql-tools   0/1     CrashLoopBackOff   11 (8s ago)   14m

下面是kubectl describe pod mssql-tool的结果:

$ kubectl describe pod mssql-tools
Name:             mssql-tools
Namespace:        default
Priority:         0
Service Account:  default
Node:             desktop-2ohsprk/172.22.97.204
Start Time:       Mon, 26 Dec 2022 04:34:19 +0500
Labels:           name=mssql-tools
Annotations:      <none>
Status:           Running
IP:               10.42.0.57
IPs:
  IP:  10.42.0.57
Containers:
  mssql-tools:
    Container ID:   docker://76343010f4344a5d26fb35f3b0278271d3336e8e10d695cc22e78520262f34bf
    Image:          mcr.microsoft.com/mssql-tools:latest
    Image ID:       docker-pullable://mcr.microsoft.com/mssql-tools@sha256:62556500522072535cb3df2bb5965333dded9be47000473e9e0f84118e248642
    Port:           <none>
    Host Port:      <none>
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Mon, 26 Dec 2022 04:46:20 +0500
      Finished:     Mon, 26 Dec 2022 04:46:20 +0500
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Mon, 26 Dec 2022 04:45:51 +0500
      Finished:     Mon, 26 Dec 2022 04:45:51 +0500
    Ready:          False
    Restart Count:  9
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-wkqlg (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  kube-api-access-wkqlg:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason          Age                   From               Message
  ----     ------          ----                  ----               -------
  Normal   Scheduled       12m                   default-scheduler  Successfully assigned default/mssql-tools to desktop-2ohsprk
  Normal   Pulled          12m                   kubelet            Successfully pulled image "mcr.microsoft.com/mssql-tools:latest" in 1.459473213s
  Normal   Pulled          12m                   kubelet            Successfully pulled image "mcr.microsoft.com/mssql-tools:latest" in 823.403008ms
  Normal   Pulled          11m                   kubelet            Successfully pulled image "mcr.microsoft.com/mssql-tools:latest" in 835.697509ms
  Normal   Pulled          11m                   kubelet            Successfully pulled image "mcr.microsoft.com/mssql-tools:latest" in 873.802598ms
  Normal   Created         11m (x4 over 12m)     kubelet            Created container mssql-tools
  Normal   Started         11m (x4 over 12m)     kubelet            Started container mssql-tools
  Normal   Pulling         10m (x5 over 12m)     kubelet            Pulling image "mcr.microsoft.com/mssql-tools:latest"
  Normal   Pulled          10m                   kubelet            Successfully pulled image "mcr.microsoft.com/mssql-tools:latest" in 740.64559ms
  Warning  BackOff         6m56s (x25 over 11m)  kubelet            Back-off restarting failed container
  Normal   SandboxChanged  50s                   kubelet            Pod sandbox changed, it will be killed and re-created.
  Normal   Pulled          48s                   kubelet            Successfully pulled image "mcr.microsoft.com/mssql-tools:latest" in 951.332457ms
  Normal   Pulled          32s                   kubelet            Successfully pulled image "mcr.microsoft.com/mssql-tools:latest" in 828.839917ms
  Normal   Pulling         4s (x3 over 49s)      kubelet            Pulling image "mcr.microsoft.com/mssql-tools:latest"
  Normal   Pulled          3s                    kubelet            Successfully pulled image "mcr.microsoft.com/mssql-tools:latest" in 713.951656ms
  Normal   Created         3s (x3 over 48s)      kubelet            Created container mssql-tools
  Normal   Started         3s (x3 over 48s)      kubelet            Started container mssql-tools
  Warning  BackOff         2s (x5 over 47s)      kubelet            Back-off restarting failed container

如果我通过docker运行同一个容器,它就可以完美地工作,并且我可以使用它的shell来正确地执行sqlcmd
我想不出任何理由。
任何帮助都将不胜感激。谢谢

rvpgvaaj

rvpgvaaj1#

Crashloopbackoff是常见错误,表示pod无法启动,并且当kubernetes尝试重新启动时,pod继续反复失败。
要解决此问题,请执行以下步骤:
1.通过运行命令Run kubectl describe pod [name]检查“退出重新启动失败的容器”。
如果您从kubelet收到Liveness探测失败和Back-off restarting failed container消息,则表明container没有响应,正在重新启动。
1.从上一个容器示例检查。运行kubectl get pods以确定导致CrashLoopBackOff错误的Kubernetes pod。您可以运行kubectl logs --previous --tail 10命令以获取pod的最后十个日志行。
1.通过运行以下命令检查部署日志:kubectl logs -f deploy/ -n
有关更详细的故障诊断步骤,请参阅此link

envsm3lx

envsm3lx2#

因此,在尝试和挖掘了多个选项后,最后通过执行命令sleep 3600000(即延迟它,以便pod正确地初始化自己,然后执行容器)来工作。

apiVersion: v1
kind: Pod
metadata:
  name: mssql-tools
  labels:
    name: mssql-tools
spec:
  containers:    
  - name: mssql-tools
    image: mcr.microsoft.com/mssql-tools:latest
    command: ["sleep"]
    args:
      - "3600000"
    imagePullPolicy: IfNotPresent

命令和参数传递部分也可以如下所述:

apiVersion: v1
...
...
spec:
  containers:    
  - name: mssql-tools
    image: mcr.microsoft.com/mssql-tools:latest
    command:
      - sleep
      - "3600000"
...

和btw,您还可以通过使用kubectl run命令行传递命令来部署容器:即

kubectl run mssql --image=mcr.microsoft.com/mssql-tools --command sleep 3600000 -n myNameSpace

**注意:**如果不将-n myNameSpace部署在特定名称空间或default namespace中,则可以省略-n myNameSpace

相关问题