Namespace
Think of a Namespace as a virtual cluster or compartment housing a collection of related resources and objects. This concept allows you to group and categorize entities like deployments, pods, services, and replication controllers based on projects or user groups. By default, these all belong to the 'default' namespace. However, 'nodes', 'persistent volumes', and namespaces themselves are not subordinate to any namespace.
You might find Namespaces being put to use to isolate users. For instance, Kubernetes' built-in services typically run in the kube-system namespace.
Mastering Namespace Operations
The Kubernetes command-line tool
kubectllets you specify a namespace using the--namespaceor shorter-noption. If you don't specify one, it assumes 'default'. To view resources across all namespaces, set--all-namespace=true.
Searching
$ kubectl get namespaces
NAME STATUS AGE
default Active 11d
kube-system Active 11dNote: Keep an eye on the status - it'll indicate if a namespace is "Active" or in the process of being "Terminated". During the deletion process, the namespace status changes to "Terminating".
Creating
(1) Go ahead and create it directly from the command line:
$ kubectl create namespace new-namespace
(2) Or play it traditional and create it via a file:
$ cat my-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: new-namespace
$ kubectl create -f ./my-namespace.yamlNote: Make sure your namespace name matches this regular expression [a-z0-9]([-a-z0-9]*[a-z0-9])? and doesn't exceed 63 characters in length.
Deleting
$ kubectl delete namespaces new-namespaceTake heed:
Deleting a namespace automatically takes out all the resources belonging to that namespace as well.
The
defaultandkube-systemnamespaces are off-limits for deletion.While a PersistentVolume doesn't belong to any namespace, a PersistentVolumeClaim is tied to a specific namespace.
The namespace association of an Event depends on its source object.
With version v1.7 came the
kube-publicnamespace for storing public information, usually in the form of ConfigMaps.
$ kubectl get configmap -n=kube-public
NAME DATA AGE
cluster-info 2 29dFor Further Reading
最后更新于