Kubernetes kubectl delete 命令详解

6 篇文章 0 订阅

Kubernetes kubectl delete 命令详解
1 kubectl delete
2 语法
3 示例
4 Flags
kubectl delete
通过配置文件名、stdin、资源名称或label选择器来删除资源。

支持JSON和YAML格式文件。可以只指定一种类型的参数:文件名、资源名称或label选择器。

有些资源,如pod,支持优雅的(graceful)删除,因为这些资源一般是集群中的实体,所以删除不可能会立即生效,这些资源在强制终止之前默认定义了一个周期(宽限期),但是你可以使用–grace-period flag来覆盖该值,或者通过pass --now设置该周期为1。

如果托管Pod的Node节点已经停止或者无法连接API Server,使用delete命令删除Pod需等待时间更长。要强制删除资源,需指定- force flag,且设置周期(宽限期)为0。

如果执行强制删除Pod,则调度程序会在节点释放这些Pod之前将新的Pod放在这些节点上,并使之前Pod立即被逐出。

注意:执行delete命令时不会检查资源版本,如果在执行delete操作时有人进行了更新操作,那么更新操作将连同资源一起被删除。

语法
$ delete ([-f FILENAME] | TYPE [(NAME | -l label | --all)])
示例
使用 pod.json中指定的资源类型和名称删除pod。

kubectl delete -f ./pod.json
根据传入stdin的JSON所指定的类型和名称删除pod。

cat pod.json | kubectl delete -f -
删除名为“baz”和“foo”的Pod和Service。

kubectl delete pod,service baz foo
删除 Label name = myLabel的pod和Service。

kubectl delete pods,services -l name=myLabel
强制删除dead node上的pod

kubectl delete pod foo --grace-period=0 --force
删除所有pod

kubectl delete pods --all
Flags
Name Shorthand Default Usage
all false select all resources in the namespace of the specified resource types.
cascade true If true, cascade the deletion of the resources managed by this resource (e.g. Pods created by a ReplicationController). Default true.
filename f [] Filename, directory, or URL to files containing the resource to delete.
force false Immediate deletion of some resources may result in inconsistency or data loss and requires confirmation.
grace-period -1 Period of time in seconds given to the resource to terminate gracefully. Ignored if negative.
ignore-not-found false Treat “resource not found” as a successful delete. Defaults to “true” when --all is specified.
include-extended-apis true If true, include definitions of new APIs via calls to the API server. [default true]
now false If true, resources are signaled for immediate shutdown (same as --grace-period=1).
output o Output mode. Use “-o name” for shorter output (resource/name).
recursive R false Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
selector l Selector (label query) to filter on.
timeout 0s The length of time to wait before giving up on a delete, zero means determine a timeout from the size of the object

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
kubectlKubernetes的命令行工具,用于与Kubernetes集群进行交互和管理。下面是kubectl的一些常用命令及其详解: 1. kubectl get:用于获取资源的信息。例如,使用kubectl get pods可以获取当前集群中所有的Pod信息。 2. kubectl create:用于创建资源。例如,使用kubectl create deployment可以创建一个新的Deployment。 3. kubectl apply:用于应用配置文件或更新资源。例如,使用kubectl apply -f deployment.yaml可以应用一个Deployment的配置文件。 4. kubectl describe:用于查看资源的详细信息。例如,使用kubectl describe pod my-pod可以查看名为my-pod的Pod的详细信息。 5. kubectl delete:用于删除资源。例如,使用kubectl delete pod my-pod可以删除名为my-pod的Pod。 6. kubectl exec:用于在容器内执行命令。例如,使用kubectl exec my-pod -- ls可以在名为my-pod的Pod中执行ls命令。 7. kubectl logs:用于查看容器的日志。例如,使用kubectl logs my-pod可以查看名为my-pod的Pod中容器的日志。 8. kubectl port-forward:用于将本地端口与Pod或Service的端口进行转发。例如,使用kubectl port-forward my-pod 8080:80可以将本地的8080端口与名为my-pod的Pod中的80端口进行转发。 9. kubectl scale:用于调整资源的副本数。例如,使用kubectl scale deployment/my-deployment --replicas=3可以将名为my-deployment的Deployment的副本数调整为3。 10. kubectl rollout:用于管理资源的滚动更新。例如,使用kubectl rollout restart deployment/my-deployment可以重新启动名为my-deployment的Deployment。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值