我已经用命令启动了豆荚

$ kubectl run busybox \
--image=busybox \
--restart=Never \
--tty \
-i \
--generator=run-pod/v1

出了点问题,现在我没法删除这个Pod了。

我尝试使用下面描述的方法,但Pod不断被重新创建。

$ kubectl delete pods  busybox-na3tm
pod "busybox-na3tm" deleted

$ kubectl get pods
NAME                                     READY     STATUS              RESTARTS   AGE
busybox-vlzh3                            0/1       ContainerCreating   0          14s

$ kubectl delete pod busybox-vlzh3 --grace-period=0

$ kubectl delete pods --all
pod "busybox-131cq" deleted
pod "busybox-136x9" deleted
pod "busybox-13f8a" deleted
pod "busybox-13svg" deleted
pod "busybox-1465m" deleted
pod "busybox-14uz1" deleted
pod "busybox-15raj" deleted
pod "busybox-160to" deleted
pod "busybox-16191" deleted

$ kubectl get pods --all-namespaces
NAMESPACE   NAME            READY     STATUS              RESTARTS   AGE
default     busybox-c9rnx   0/1       RunContainerError   0          23s

当前回答

Kubernetes总是以这样的格式工作:

部署>>> replicsets >>> pods

首先用0个副本编辑部署,然后用所需的副本扩展部署(运行下面的命令)。您将看到新的副本集已经创建,pod也将以所需的计数运行。

*

在linux中:~ anuragmanikkame$ kubectl scale deploy tomcat -n Dev-namespace——replicas=2部署。扩展/ tomcat缩放


其他回答

基本上有两种方法可以移除pod

Kubectl scale——replicas=0部署name_of_deployment。 这将设置副本的数量为0,因此它将不会重新启动pod。 使用helm卸载您在管道中实现的图表。 不要直接删除部署,而是使用helm卸载图表,这将删除它创建的所有对象。

还要注意有状态集

kubectl get sts --all-namespaces

删除命名空间中的所有有状态集

kubectl --namespace <yournamespace> delete sts --all

一个一个地删除它们

kubectl --namespace ag1 delete sts mssql1 
kubectl --namespace ag1 delete sts mssql2
kubectl --namespace ag1 delete sts mssql3

这里的许多答案都告诉我们删除一个特定的k8s对象,但你可以一次删除多个对象,而不是一个一个地删除:

Kubectl删除部署、作业、服务、pods——所有-n <命名空间>

在我的例子中,我使用OLM -操作员生命周期管理器运行OpenShift集群。OLM是控制部署的人,所以当我删除部署时,它不足以阻止pods重新启动。

只有当我删除OLM及其订阅时,部署、服务和pod才消失了。

首先列出命名空间中的所有k8s对象:

$ kubectl get all -n openshift-submariner

NAME                                       READY   STATUS    RESTARTS   AGE
pod/submariner-operator-847f545595-jwv27   1/1     Running   0          8d  
NAME                                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/submariner-operator-metrics   ClusterIP   101.34.190.249   <none>        8383/TCP   8d
NAME                                  READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/submariner-operator   1/1     1            1           8d
NAME                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/submariner-operator-847f545595   1         1         1       8d

OLM没有与get all一起列出,所以我专门搜索了它:

$ kubectl get olm -n openshift-submariner

NAME                                                      AGE
operatorgroup.operators.coreos.com/openshift-submariner   8d
NAME                                                             DISPLAY      VERSION
clusterserviceversion.operators.coreos.com/submariner-operator   Submariner   0.0.1 

现在删除所有对象,包括olm、订阅、部署、副本集等:

$ kubectl delete olm,svc,rs,rc,subs,deploy,jobs,pods --all -n openshift-submariner

operatorgroup.operators.coreos.com "openshift-submariner" deleted
clusterserviceversion.operators.coreos.com "submariner-operator" deleted
deployment.extensions "submariner-operator" deleted
subscription.operators.coreos.com "submariner" deleted
service "submariner-operator-metrics" deleted
replicaset.extensions "submariner-operator-847f545595" deleted
pod "submariner-operator-847f545595-jwv27" deleted

再次列出对象-全部消失:

$ kubectl get all -n openshift-submariner
No resources found.

$ kubectl get olm -n openshift-submariner
No resources found.

很明显,有什么东西在复活荚果。虽然很多其他的答案让你看一切(复制集,作业,部署,有状态集,…)来找到可能重生pod的东西,但你可以只看pod,看看是什么衍生了它。例如:

$ kubectl describe pod $mypod | grep 'Controlled By:'
Controlled By:  ReplicaSet/foobar

这告诉你是什么创造了这个豆荚。然后你可以删除它。

在学习了一个交互式教程后,我最终得到了一堆pod、服务和部署:

me@pooh ~ > kubectl get pods,services
NAME                                       READY   STATUS    RESTARTS   AGE
pod/kubernetes-bootcamp-5c69669756-lzft5   1/1     Running   0          43s
pod/kubernetes-bootcamp-5c69669756-n947m   1/1     Running   0          43s
pod/kubernetes-bootcamp-5c69669756-s2jhl   1/1     Running   0          43s
pod/kubernetes-bootcamp-5c69669756-v8vd4   1/1     Running   0          43s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   37s
me@pooh ~ > kubectl get deployments --all-namespaces
NAMESPACE     NAME                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
default       kubernetes-bootcamp   4         4         4            4           1h
docker        compose               1         1         1            1           1d
docker        compose-api           1         1         1            1           1d
kube-system   kube-dns              1         1         1            1           1d

要清理所有内容,删除—一切正常:

me@pooh ~ > kubectl delete pods,services,deployments --all
pod "kubernetes-bootcamp-5c69669756-lzft5" deleted
pod "kubernetes-bootcamp-5c69669756-n947m" deleted
pod "kubernetes-bootcamp-5c69669756-s2jhl" deleted
pod "kubernetes-bootcamp-5c69669756-v8vd4" deleted
service "kubernetes" deleted
deployment.extensions "kubernetes-bootcamp" deleted

这给我留下了一个空的Kubernetes集群:

me@pooh ~ > kubectl get pods,services,deployments
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   8m