一看必会系列:kubernetes 正确的删除pod的方式

来源:本站原创 容器技术 超过19 views围观 0条评论

查看所有pods

[root@centos011 ~]# kubectl get pods
NAME                          READY     STATUS              RESTARTS   AGE
jeffnginx-946323625-6bjz8     1/1       Running             0          46s
jeffnginx1-3759915275-fbv90   0/1       ContainerCreating   0          21h
jeffnginx2-521453951-5r0g4    0/1       ContainerCreating   0          21h
nginx-controller-7bxpx        0/1       ContainerCreating   0          21h
nginx-controller-fl3kf        0/1       ContainerCreating   0          21h

用delete一个一个删除
[root@centos011 ~]# kubectl delete pods jeffnginx1-3759915275-fbv90
pod "jeffnginx1-3759915275-fbv90" deleted
[root@centos011 ~]# kubectl delete pods jeffnginx2-521453951-5r0g4
pod "jeffnginx2-521453951-5r0g4" deleted
[root@centos011 ~]# kubectl delete pods nginx-controller-7bxpx
pod "nginx-controller-7bxpx" deleted
[root@centos011 ~]# kubectl delete pods nginx-controller-fl3kf
pod "nginx-controller-fl3kf" deleted
[root@centos011 ~]#

发现所有pod会自己起来这是repolic 的机制很正确。这是正是确保replicas为1的动作。

[root@centos011 ~]# kubectl get pods
NAME                          READY     STATUS              RESTARTS   AGE
jeffnginx-946323625-6bjz8     1/1       Running             0          1m
jeffnginx1-3759915275-v5791   1/1       Running             0          47s
jeffnginx2-521453951-hgc8z    0/1       ContainerCreating   0          37s
nginx-controller-l67nm        0/1       ImagePullBackOff    0          30s
nginx-controller-pmrxf        0/1       ContainerCreating   0          22s

[root@centos011 ~]# kubectl get pods
NAME                          READY     STATUS              RESTARTS   AGE
jeffnginx-946323625-6bjz8     1/1       Running             0          3m
jeffnginx1-3759915275-v5791   1/1       Running             0          2m
jeffnginx2-521453951-hgc8z    0/1       ContainerCreating   0          1m
nginx-controller-l67nm        0/1       ErrImagePull        0          1m
nginx-controller-pmrxf        0/1       ContainerCreating   0          1m

使用deployments 命令

[root@centos011 ~]# kubectl get deployments
NAME         DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
jeffnginx    1         1         1            1           23h
jeffnginx1   1         1         1            1           22h
jeffnginx2   1         1         1            0           22h
[root@centos011 ~]# kubectl delete deployment jeffnginx
deployment "jeffnginx" deleted
[root@centos011 ~]# kubectl delete deployment jeffnginx1
deployment "jeffnginx1" deleted
[root@centos011 ~]# kubectl delete deployment jeffnginx2
deployment "jeffnginx2" deleted

删除后pods将不在存在
[root@centos011 ~]# kubectl get deployments
No resources found.
[root@centos011 ~]#

查看除了pod的资源 kubectl get rc,service

[root@centos011 ~]# kubectl get rc,service
NAME                  DESIRED   CURRENT   READY     AGE
rc/nginx-controller   2         2         0         22h   两个rc服务

NAME             CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
svc/kubernetes   192.168.142.1   <none>        443/TCP   9d  一个Service服务

[root@centos011 ~]# kubectl delete rc –all

删除service 命令
[root@centos011 ~]# kubectl get service
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
kubernetes   192.168.142.1   <none>        443/TCP   32s
[root@centos011 ~]# kubectl delete services kubernetes
service "kubernetes" deleted
[root@centos011 ~]#
[root@centos011 ~]#
[root@centos011 ~]# kubectl get service
No resources found.
[root@centos011 ~]#

官方命令
[root@centos011 ~]# kubectl get service –all
Error: unknown flag: –all

Examples:
  # List all pods in ps output format.
  kubectl get pods
 
  # List all pods in ps output format with more information (such as node name).
  kubectl get pods -o wide
 
  # List a single replication controller with specified NAME in ps output format.
  kubectl get replicationcontroller web
 
  # List a single pod in JSON output format.
  kubectl get -o json pod web-pod-13je7
 
  # List a pod identified by type and name specified in "pod.yaml" in JSON output format.
  kubectl get -f pod.yaml -o json
 
  # Return only the phase value of the specified pod.
  kubectl get -o template pod/web-pod-13je7 –template={{.status.phase}}
 
  # List all replication controllers and services together in ps output format.
  kubectl get rc,services
 
  # List one or more resources by their type and names.
  kubectl get rc/web service/frontend pods/web-pod-13je7

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=3832转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点

暂时还木有人评论,坐等沙发!
发表评论

快捷键:Ctrl+Enter