Problem scenario
You have heard of namespaces in programming, DNS, AWS, operating systems, and in the context of managing containers. You want to see the disambiguation of of this term insofar as computing is concerned. What are namespaces in I.T.?
Overview
Names can be bound to different spaces (or subsystems), and this binding varies depending on the technology. Namespacing helps facilitate locally unique identification/resolution of names. Projects can scale with independent contributors re-using names that are not globally unique without interfering with each other because of namespaces.
Answer: Namespaces for Programming
"Namespaces in programming terminology are essentially "containers" that help you organize things like methods and classes. The usefulness of namespaces becomes more apparent as the programs you write become more and more complex and you start to make use of libraries and classes provided by other programmers--it becomes a useful tool to have objects and methods use descriptive and helpful naming schemes." This quote was taken from page 38 of Customizing Chef.
Namespaces are used in languages such as C++, Java, Python, and Ruby.
"A namespace is a set of names (identifiers) in which each name is unique." (Taken from page 1104 in a section on Python programming in A Practical Guide to Fedora and Red Hat Enterprise Linux.)
"A namespace is a self-contained package of variables, which are known as the attributes of the namespace object." (Taken from page 686 of Python Programming.)
In Python there is a lexical evaluation referred to as LEGB. This governs how identifiers/names are evaluated based on their scope or namespace.
"The LEGB rule is used to decide the order in which the namespaces are to be searched for scope resolution." (Taken from medium.com.) To learn more, see What is the Difference between global and nonlocal in Python?.
The LEGB identifier evaluation system for Python is a namcespace rule; in some ways this rule is different from namespace packages that Python uses via the "import" statement. When you use an "import" statement, words you use in your Python program can be matched/identified and evaluated when they otherwise wouldn't be.
If you try to run a statement with the word "requests" in a Python program without an "import requests" statement, you will get this error:
NameError: name 'requests' in not defined
You must import the requests namespace package first to avoid an error such as the one above.
Answer: Namespaces for DNS
DNS namespace or domain namespace is a reference to words separated by dots "." in a URL near the hostname. For example http://portal.continualintegration.com/ shows "portal" as a name in the continualintegration.com namespace. This concept is explained in detail here.
Answer: Namespaces for AWS
"A namespace is a way to group services for an application. When you create a namespace, you specify how you want to discover service instances that you register with AWS Cloud Map: using API calls or using DNS queries. You also specify the name that you want your application to use to discover instances. " (Taken from official AWS documentation.)
If you have the AWS CLI installed, you can view the namespaces with this command:aws servicediscovery list-namespaces
Answer: Namespaces for Operating Systems
"A namespace is a set of names (identifiers) in which each name is unique." (Taken from page 37 of A Practical Guide to Fedora and Red Hat Enterprise Linux.)
Running processes can be separated at the Linux OS level. To see the inode number for a given name space on a Linux OS, use the lsns
command. To learn about this command, see this posting.
If you want to list the namespaces in your Linux OS, see this posting (assuming you have installed the util-linux package).
To see the network namespaces on a Linux OS, see this this external page.
Answer: Namespaces for Containers
There are six types of namespaces for Docker containers: mount, UTS, IPC, PID, network and user. Namespaces and cgroups are components that do isolation for the containers.
"[N]amespaces allow for processes to use identically named resources and isolate them from each other's view of the system" according to page 156 of Docker Up and Running.
Mount namespaces are used by Docker "to make your container look like it has its entire own filesystem namespace." (This quote was taken from page 161 of Docker Up and Running.)
UTS namespaces were "[n]amed for the kernel structure they namespace, and ultimately from the "unix Timesharing System," UTS namespaces give your container its own hostname and domain name." (This quote was taken from page 161 of Docker Up and Running.)
Interprocess communication namespaces (better known as IPC namespaces) are created by Docker. Each Docker container gets a unique IPC namespace (according to https://dzone.com/articles/docker-in-action-the-shared-memory-namespace).
"PID namespace provides separation of processes. The PID Namespace removes the view of the system processes, and allows process ids to be reused including pid 1." (Taken from https://docs.docker.com/engine/reference/run/.)
Network namespace separates IP addresses and routing tables of Docker containers. To learn more, see this edureka.com posting or this platform9.com posting.
"User namespaces are used with containers to make it possible to setup a container without privileged operations, and so that a normal user can act as root inside a container to perform administrative tasks, without being root on the host outside." (This was taken from an external website.) User namespaces isolate users and groups in Docker containers from the Docker host server (according to page 162 of Docker Up and Running). To read more about them, see this posting.
Answer: Namespaces for Container Orchestration
"Using multiple namespaces allows you to split complex systems with numerous components into smaller distinct groups." (Taken from page 77 of Kubernetes in Action.)
"…there are actually three namespaces that Kubernetes ships with: default, kube-system (used for Kubernetes components), and kube-public (used for public resources)." (This quote was taken from https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-organizing-with-namespaces.)
The command kubectl get ns
will list the namespaces.
Docker Swarm may not have namespaces, "Docker Swarm stacks are, in a way, similar to Kubernetes Namespaces. All the services in a stack are uniquely identified through a combination of a stack name and the names of services inside it. By default, all services within a stack can communicate with each other through the stack's default network. Services can speak with those from other stacks only if they are explicitly attached to the same network. All in all, each Swarm stack is separated from other stacks. They are, in a way, similar to Kubernetes Namespaces." This quote was taken from this site.
To learn more about different types of namespaces in general, you may want to see this Webopedia.com posting.
Answer: Namespaces for Puppet
A namespace in Puppet is defined by the scope of a module, class or other defined type.
In Puppet you have classes and defined types; these are in a namespace of the outermost class or definition (according to https://puppet.com/docs/puppet/7.4/lang_namespaces.html). Nested classes are not recommended however (according to https://puppet.com/docs/puppet/7.4/lang_namespaces.html).
The define
key word enables you to define a type; to read more, see this posting.
Answer: Namespaces for XML Files
A namespace in XML allows for local names to be re-used like other namespaces. Some projects/solutions with XML will include independent contributors. Below are partial quotes and one paraphrase taken from w3.org that explain what an XML namespace is.
"Namespaces are a mechanism for managing names in a distributed way that greatly reduces the likelihood that two" people will create a conflicting name.
"An XML namespace has a namespace name (a ...[Uniform Resource Identifier]...) and a set of local names..."