k8s常用指令续:

3.命名空间

root@k8s-master pods\]# kubectl create namespace abc //创建命名空间 namespace/abc created \[root@k8s-master pods\]# kubectl get namespaces //查看命名空间 NAME STATUS AGE abc Active 24s default Active 10h kube-node-lease Active 10h kube-public Active 10h kube-system Active 10h kubernetes-dashboard Active 9h \[root@k8s-master pods\]# kubectl create -f abc.json --namespace abc //使用文件创建pod并指定命名空间 pod/busybox-sleep000 created 或者在文件中指定,必须先在外面创建好命名空间才可以 \[root@k8s-master pods\]# vim abc.yaml apiVersion: v1 kind: Pod metadata: name: busybox-sleep namespace: abc spec: containers: - name: busybox image: busybox:1.28 args: - sleep - "1000" \[root@k8s-master pods\]# kubectl create -f abc.yaml pod/busybox-sleep created \[root@k8s-master pods\]# kubectl delete namespaces abc //删除命名空间,同时也会删除命名空间下的pod namespace "abc" deleted ### 4.kubectl delete kubernetes 集群中,可通过指定配置文件(json/yaml)、stdin(标准输入)、资源名称或 label(标签)来删除资源。 Pod 支持平滑删除,因为这些资源一般是集群中的实体,所以删除无法立即生效,这些资源在强制终止之前默认定义了一个周期 (宽限期),但可以使用"-graceperiod flag"来覆盖该值,或通过"pass --now"设置该周期为 1. 如果托管 Pod 的 Node 节点已停止或无法连接 APIServer,使用 delete 删除 Pod 需等待时间更长,此时要 想强制删除,需指定"-force flag",且设置周期为 0。 注意:执行delete命令时不会检查资源版本,如果在执行delete操作时有人进行了更新操作,那么更新操作将连同资源一起被删除。 语法 kubectl delete (\[ -f 文件名 \] \| 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 # 删除⼀个部署集 kubectl delete deployments nginx ### 5.kubectl get 语法: kubectl get resource_name(资源名、类型) 常见 resource_name:

相关推荐
春风有信43 分钟前
【2026.05.01】Windows10安装Docker Desktop 4.71.0.0步骤及问题解决
运维·docker·容器
sthnyph5 小时前
docker compose安装redis
redis·docker·容器
AIMath~5 小时前
雪花算法+ZooKeeper解决方案+RPC是什么
分布式·zookeeper·云原生
W.A委员会6 小时前
Docker基本使用流程
运维·docker·容器
gwjcloud7 小时前
Kubernetes从入门到精通(进阶篇)03
云原生·容器·kubernetes
GuokLiu7 小时前
260502-Clawith-Docker安装过程
运维·docker·容器·claw
日取其半万世不竭8 小时前
PeerTube 部署指南:自建视频托管平台
云原生·eureka·音视频
JesseDev8 小时前
Docker lnmp环境快速搭建开箱即用
运维·docker·容器
小义_9 小时前
【Kubernetes】(十二)配置存储卷
云原生·容器·kubernetes