一、增
创建一个命名空间 名称叫 test
#kubectl create namespace test
#kubectl create ns test
二、删
删除一个命名空间
#kubectl delete ns test
删除多个命名空间
[root@master ~]# kubectl get ns
NAME STATUS AGE
default Active 4d1h
kube-node-lease Active 4d1h
kube-public Active 4d1h
kube-system Active 4d1h
test1 Active 18s
test2 Active 2s
#kubectl delete ns/test1 ns/test2
三、查
1、查看命名空间
#kubectl get ns
2、查看具体的命名空间
#kubectl get ns/kube-system
3、查看具体的命名空间 长格式
#kubectl get ns/kube-system -o wide
4、查看命名空间以 yaml 格式输出
[root@master ~]# kubectl get ns/kube-system -o yaml
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: "2019-11-14T05:54:54Z"
name: kube-system
resourceVersion: "6"
selfLink: /api/v1/namespaces/kube-system
uid: 5a74d4f9-ae6d-4807-91bf-1cab7a6e5b10
spec:
finalizers:
- kubernetes
status:
phase: Active
5、查看命名空间以 json 格式输出
[root@master ~]# kubectl get ns/kube-system -o json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"creationTimestamp": "2019-11-14T05:54:54Z",
"name": "kube-system",
"resourceVersion": "6",
"selfLink": "/api/v1/namespaces/kube-system",
"uid": "5a74d4f9-ae6d-4807-91bf-1cab7a6e5b10"
},
"spec": {
"finalizers": [
"kubernetes"
]
},
"status": {
"phase": "Active"
}
}
6、输出一个命名空间的描述信息
#kubectl describe ns/kube-system
kubectl create namespace test