热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

k8snamespace(名称空间)操作

k8snamespace(名称空间)操作查询namespace创建namespace删除namespace查询namespace命令kubectlge


k8s namespace(名称空间)操作

  • 查询namespace
  • 创建namespace
  • 删除namespace


查询namespace

命令kubectl get ns或者kubectl get namespaces
案例:

[root@123 ~]# kubectl get namespaces
NAME STATUS AGE
default Active 3h40m
kube-node-lease Active 3h40m
kube-public Active 3h40m
kube-system Active 3h40m

创建namespace

命令: kubectl create -f $namespace.yamlkubectl create namespace $namespace
yaml文件:

[root@123 ~]# cat test-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:name: test-ns

创建案例:

#使用yaml创建名称空间
[root@123 ~]# kubectl create -f test-namespace.yaml
test-ns created
[root@123 ~]# kubectl get ns
NAME STATUS AGE
default Active 3h45m
kube-node-lease Active 3h45m
kube-public Active 3h45m
kube-system Active 3h45m
test-ns Active 18s# 使用命令创建名称空间
[root@123 ~]# kubectl create namespace custom-namespace
custom-namespace created
[root@123 ~]# kubectl get ns
NAME STATUS AGE
custom-namespace Active 11s
default Active 3h49m
kube-node-lease Active 3h49m
kube-public Active 3h49m
kube-system Active 3h49m
test-ns Active 4m1s
[root@123 ~]# kubectl describe ns custom-namespace
Name: custom-namespace
Labels: kubernetes.io/metadata.name=custom-namespace
Annotations:
Status: Active
No resource quota.
No LimitRange resource.

注意:命名空间名称不允许包含点(.)



删除namespace

命令:kubectl delete ns $namespace
案例:

[root@123 ~]# kubectl get ns
NAME STATUS AGE
custom-namespace Active 11s
default Active 3h49m
kube-node-lease Active 3h49m
kube-public Active 3h49m
kube-system Active 3h49m
test-ns Active 4m1s[root@123 ~]# kubectl delete ns custom-namespacenamespace"custom-namespace" deleted[root@123 ~]# kubectl get ns
NAME STATUS AGE
default Active 3h55m
kube-node-lease Active 3h55m
kube-public Active 3h55m
kube-system Active 3h55m
test-ns Active 10m

注意:因为pod等资源是在namespace下创建的,如果namespace删除,那么其中的pod、service等资源也将被同时清除,删除时要慎重



推荐阅读
author-avatar
Pisces2lemon
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有