首页 > 解决方案 > How to stop/start containers at k3s agent?

问题描述

Docker provides the following functions to stop and start the same container.

OP46B1:/ # docker stop 18788407a60c
OP46B1:/ # docker ps -a                                                                                                      
  CONTAINER ID  IMAGE   COMMAND   CREATED       STATUS    PORTS      NAMES                                                                                                                      
  18788407a60c ubuntu:test "/bin/bash" 34 minutes ago Exited (0) 7 seconds ago charming_gagarin
OP46B1:/ # docker start 18788407a60c

But k3s agent does not provide this function. A container stopped by "k3s crictl stop" cannot be restarted by "k3s crictl start". The following error will appear. How to stop and start the same container at k3s agent?

OP46B1:/data # ./k3s-arm64 crictl stop 5485f899c7bb6
  5485f899c7bb6
OP46B1:/data # ./k3s-arm64 crictl ps -a
  CONTAINER  IMAGE  CREATED  STATE NAME  ATTEMPT POD ID
  5485f899c7bb6 b58be220837f0 3 days ago  Exited  pod-webapp86  0 92a94e8eec410
OP46B1:/data# ./k3s-arm64 crictl start 5485f899c7bb6
  FATA[2020-10-20T00:54:04.520056930Z] Starting the container "5485f899c7bb6" failed: rpc error: code = Unknown desc = failed to set starting state for container "5485f899c7bb6f2d294a3a131b33d8f35c9cf84df73cacb7b8af1ee48a591dcf": container is in CONTAINER_EXITED state

标签: kubernetescontainersk3s

解决方案


k3s 是 kubernetes 的一个发行版。Kubernetes 是对容器框架(containerd/docker/etc.)的抽象。因此,您不应该尝试直接使用 来控制容器k3s crictl,而应使用 kubernetes 提供的 pod 抽象。

k3s kubectl get pods -A将列出当前在 k3s 实例中运行的所有 pod。1
k3s kubectl delete pod -n <namespace> <pod-selector>将删除指定的 pod,这将停止(并删除)它们的容器。2


推荐阅读