一看必會系列:kubernetes 正確的刪除pod的方式

來源:本站原創 容器技術 超過416 views圍觀 0條評論

查看所有pods

[[email protected] ~]# 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一個一個刪除
[[email protected] ~]# kubectl delete pods jeffnginx1-3759915275-fbv90
pod "jeffnginx1-3759915275-fbv90" deleted
[[email protected] ~]# kubectl delete pods jeffnginx2-521453951-5r0g4
pod "jeffnginx2-521453951-5r0g4" deleted
[[email protected] ~]# kubectl delete pods nginx-controller-7bxpx
pod "nginx-controller-7bxpx" deleted
[[email protected] ~]# kubectl delete pods nginx-controller-fl3kf
pod "nginx-controller-fl3kf" deleted
[[email protected] ~]#

發現所有pod會自己起來這是repolic 的機制很正確。這是正是確保replicas為1的動作。

[[email protected] ~]# 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

[[email protected] ~]# 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 命令

[[email protected] ~]# 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
[[email protected] ~]# kubectl delete deployment jeffnginx
deployment "jeffnginx" deleted
[[email protected] ~]# kubectl delete deployment jeffnginx1
deployment "jeffnginx1" deleted
[[email protected] ~]# kubectl delete deployment jeffnginx2
deployment "jeffnginx2" deleted

刪除后pods將不在存在
[[email protected] ~]# kubectl get deployments
No resources found.
[[email protected] ~]#

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

[[email protected] ~]# 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服務

[[email protected] ~]# kubectl delete rc –all

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

官方命令
[[email protected] ~]# 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.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=3832轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
?
?
萌宠夺宝游戏