2015-07-12 04:04:52 +00:00
|
|
|
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
|
|
|
|
|
|
|
|
<!-- BEGIN STRIP_FOR_RELEASE -->
|
|
|
|
|
2015-07-16 17:02:26 +00:00
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
|
|
|
|
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
|
|
|
|
|
|
|
|
If you are using a released version of Kubernetes, you should
|
|
|
|
refer to the docs that go with that version.
|
|
|
|
|
|
|
|
<strong>
|
2015-11-03 18:17:57 +00:00
|
|
|
The latest release of this document can be found
|
|
|
|
[here](http://releases.k8s.io/release-1.1/docs/user-guide/namespaces.md).
|
2015-07-16 17:02:26 +00:00
|
|
|
|
|
|
|
Documentation for other releases can be found at
|
|
|
|
[releases.k8s.io](http://releases.k8s.io).
|
|
|
|
</strong>
|
|
|
|
--
|
2015-07-13 22:15:35 +00:00
|
|
|
|
2015-07-12 04:04:52 +00:00
|
|
|
<!-- END STRIP_FOR_RELEASE -->
|
|
|
|
|
|
|
|
<!-- END MUNGE: UNVERSIONED_WARNING -->
|
2015-07-14 17:08:26 +00:00
|
|
|
|
2014-10-16 21:45:16 +00:00
|
|
|
# Namespaces
|
2014-08-29 16:40:18 +00:00
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
Kubernetes supports multiple virtual clusters backed by the same physical cluster.
|
|
|
|
These virtual clusters are called namespaces.
|
2015-07-14 17:08:26 +00:00
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
## When to Use Multiple Namespaces
|
2015-07-14 17:08:26 +00:00
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
Namespaces are intended for use in environments with many users spread across multiple
|
|
|
|
teams, or projects. For clusters with a few to tens of users, you should not
|
|
|
|
need to create or think about namespaces at all. Start using namespaces when you
|
|
|
|
need the features they provide.
|
2015-07-14 17:08:26 +00:00
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
Namespaces provide a scope for names. Names of resources need to be unique within a namespace, but not across namespaces.
|
2015-07-14 17:08:26 +00:00
|
|
|
|
2015-08-28 12:18:03 +00:00
|
|
|
Namespaces are a way to divide cluster resources between multiple uses (via [resource quota](../../docs/admin/resource-quota.md)).
|
2015-07-14 17:08:26 +00:00
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
In future versions of Kubernetes, objects in the same namespace will have the same
|
|
|
|
access control policies by default.
|
2015-07-14 17:08:26 +00:00
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
It is not necessary to use multiple namespaces just to separate slightly different
|
|
|
|
resources, such as different versions of the same software: use [labels](#labels.md) to distinguish
|
|
|
|
resources within the same namespace.
|
2015-07-14 17:08:26 +00:00
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
## Working with Namespaces
|
2015-07-14 17:08:26 +00:00
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
Creation and deletion of namespaces is described in the [Admin Guide documentation
|
2015-08-28 12:18:03 +00:00
|
|
|
for namespaces](../../docs/admin/namespaces.md)
|
2015-07-16 22:20:37 +00:00
|
|
|
|
2015-07-14 17:08:26 +00:00
|
|
|
### Viewing namespaces
|
2015-07-17 22:35:41 +00:00
|
|
|
|
2015-07-14 17:08:26 +00:00
|
|
|
You can list the current namespaces in a cluster using:
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:01:37 +00:00
|
|
|
```console
|
|
|
|
$ kubectl get namespaces
|
2015-07-14 17:08:26 +00:00
|
|
|
NAME LABELS STATUS
|
|
|
|
default <none> Active
|
|
|
|
kube-system <none> Active
|
|
|
|
```
|
|
|
|
|
|
|
|
Kubernetes starts with two initial namespaces:
|
2015-07-19 05:58:13 +00:00
|
|
|
* `default` The default namespace for objects with no other namespace
|
|
|
|
* `kube-system` The namespace for objects created by the Kubernetes system
|
2015-07-14 17:08:26 +00:00
|
|
|
|
|
|
|
### Setting the namespace for a request
|
|
|
|
|
2015-07-19 05:58:13 +00:00
|
|
|
To temporarily set the namespace for a request, use the `--namespace` flag.
|
2015-07-14 17:08:26 +00:00
|
|
|
|
|
|
|
For example:
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:01:37 +00:00
|
|
|
```console
|
|
|
|
$ kubectl --namespace=<insert-namespace-name-here> run nginx --image=nginx
|
|
|
|
$ kubectl --namespace=<insert-namespace-name-here> get pods
|
2015-07-14 17:08:26 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Setting the namespace preference
|
|
|
|
|
|
|
|
You can permanently save the namespace for all subsequent kubectl commands in that
|
|
|
|
context.
|
|
|
|
|
|
|
|
First get your current context:
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:01:37 +00:00
|
|
|
```console
|
|
|
|
$ export CONTEXT=$(kubectl config view | grep current-context | awk '{print $2}')
|
2015-07-14 17:08:26 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Then update the default namespace:
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:01:37 +00:00
|
|
|
```console
|
2015-11-13 10:12:50 +00:00
|
|
|
$ kubectl config set-context $CONTEXT --namespace=<insert-namespace-name-here>
|
|
|
|
# Validate it
|
|
|
|
$ kubectl config view | grep namespace:
|
2015-07-14 17:08:26 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Namespaces and DNS
|
2015-07-17 22:35:41 +00:00
|
|
|
|
2015-08-28 12:18:03 +00:00
|
|
|
When you create a [Service](services.md), it creates a corresponding [DNS entry](../admin/dns.md).
|
2015-09-06 02:45:46 +00:00
|
|
|
This entry is of the form `<service-name>.<namespace-name>.svc.cluster.local`, which means
|
2015-07-19 05:58:13 +00:00
|
|
|
that if a container just uses `<service-name>` it will resolve to the service which
|
2015-07-14 17:08:26 +00:00
|
|
|
is local to a namespace. This is useful for using the same configuration across
|
|
|
|
multiple namespaces such as Development, Staging and Production. If you want to reach
|
|
|
|
across namespaces, you need to use the fully qualified domain name (FQDN).
|
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
## Not All Objects are in a Namespace
|
2014-08-29 16:40:18 +00:00
|
|
|
|
2015-07-20 19:54:28 +00:00
|
|
|
Most kubernetes resources (e.g. pods, services, replication controllers, and others) are
|
|
|
|
in a some namespace. However namespace resources are not themselves in a namespace.
|
|
|
|
And, low-level resources, such as [nodes](../../docs/admin/node.md) and
|
|
|
|
persistentVolumes, are not in any namespace. Events are an exception: they may or may not
|
|
|
|
have a namespace, depending on the object the event is about.
|
2015-05-14 22:12:45 +00:00
|
|
|
|
|
|
|
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
2015-07-14 16:37:37 +00:00
|
|
|
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/namespaces.md?pixel)]()
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- END MUNGE: GENERATED_ANALYTICS -->
|