1.查看namespace
[root@k8s-master1 ~]# kubectl get namespaces # namespaces可以简写namespace或ns
NAME STATUS AGE
default Active 130m # 所有未指定Namespace的对象都会被默认分配在default命名空间
kube-node-lease Active 130m
kube-public Active 130m # 此命名空间下的资源可以被所有人访问
kube-system Active 130m # 所有由Kubernetes系统创建的资源都处于这个命名空间
2.查看namespace里的资源
kubectl get all --namespace=kube-system
NAME READY STATUS RESTARTS AGE
pod/calico-kube-controllers-7fdc86d8ff-cskfq 1/1 Running 3 5d1h
pod/calico-node-9dpc9 1/1 Running 2 5d1h
pod/calico-node-jdmxw 1/1 Running 3 5d1h
pod/calico-node-krwps 1/1 Running 2 5d1h
pod/calico-node-tttlr 1/1 Running 2 5d1h
pod/coredns-65dbdb44db-mm7cr 1/1 Running 2 5d1h
pod/dashboard-metrics-scraper-545bbb8767-q66bc 1/1 Running 2 5d1h
pod/kubernetes-dashboard-65665f84db-nll6k 1/1 Running 4 5d1h
pod/metrics-server-869ffc99cd-8f4jd 1/1 Running 3 5d1h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/dashboard-metrics-scraper ClusterIP 10.2.246.128 <none> 8000/TCP 5d1h
service/kube-dns ClusterIP 10.2.0.2 <none> 53/UDP,53/TCP,9153/TCP 5d1h
service/kubernetes-dashboard NodePort 10.2.213.30 <none> 443:21351/TCP 5d1h
service/metrics-server ClusterIP 10.2.232.121 <none> 443/TCP 5d1h
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/calico-node 4 4 4 4 4 beta.kubernetes.io/os=linux 5d1h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/calico-kube-controllers 1/1 1 1 5d1h
deployment.apps/coredns 1/1 1 1 5d1h
deployment.apps/dashboard-metrics-scraper 1/1 1 1 5d1h
deployment.apps/kubernetes-dashboard 1/1 1 1 5d1h
deployment.apps/metrics-server 1/1 1 1 5d1h
NAME DESIRED CURRENT READY AGE
replicaset.apps/calico-kube-controllers-7fdc86d8ff 1 1 1 5d1h
replicaset.apps/coredns-65dbdb44db 1 1 1 5d1h
replicaset.apps/dashboard-metrics-scraper-545bbb8767 1 1 1 5d1h
replicaset.apps/kubernetes-dashboard-65665f84db 1 1 1 5d1h
replicaset.apps/metrics-server-869ffc99cd 1 1 1 5d1h
3.创建namespace
3.1.命令创建
kubectl create namespace ns1
namespace/ns1 created
[root@k8s-master1 ~]# kubectl get ns
NAME STATUS AGE
default Active 5d1h
kube-node-lease Active 5d1h
kube-public Active 5d1h
kube-system Active 5d1h
ns1 Active 10s
3.2.yaml文件创建
vim create_ns2.yml
apiVersion: v1
kind: Namespace
metadata:
name: ns2
使用kubectl apply -f 创建
kubectl apply -f create_ns2.yml
namespace/ns2 created
查看
kubectl get ns
NAME STATUS AGE
default Active 5d2h
kube-node-lease Active 5d2h
kube-public Active 5d2h
kube-system Active 5d2h
ns1 Active 10m
ns2 Active 46s
4.删除namespace
4.1.命令删除
# kubectl delete namespace ns1
namespace "ns1" deleted
4.2.YAML文件删除
# kubectl delete -f create_ns2.yml
namespace "ns2" deleted