如果我们直接使用kubectl delete pod命令去简单删除1个pod是没用的

因为在deployment的replicas 中已经指定了这个pod的副本数量

gateman@k8smaster:~$ kubectl get pods
NAME                     READY   STATUS    RESTARTS       AGE
nginx-6799fc88d8-xwbnh   1/1     Running   5 (6h6m ago)   196d
gateman@k8smaster:~$ kubectl delete pod nginx-6799fc88d8-xwbnh
pod "nginx-6799fc88d8-xwbnh" deleted
gateman@k8smaster:~$ kubectl get pods
NAME                     READY   STATUS              RESTARTS   AGE
nginx-6799fc88d8-h6tkj   0/1     ContainerCreating   0          6s

可以见到, 我上面即使删除了nginx-6799fc88d8-xwbnh 这个pod, 但是1个新的pod nginx-6799fc88d8-h6tkj会被重新创建

所以我们必须从deployment 下手

用下面命令去获得k8s的deployments list

gateman@k8smaster:~$ kubectl get deployments
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   1/1     1            1           238d

### 方法1: 修改replicas 的数量为0
kubectl patch deployment nginx -p '{"spec":{"replicas":0}}'

方法2: 直接删除这个deployment

kubectl delete deployment nginx
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐