Namespaces provide for a scope of Kubernetes objects.
You can think of it as a workspace you’re sharing with other users. Many
objects such as pods and services are namespaced, while some (like nodes) are
not. As a developer you’d usually simply use an assigned namespace, however
admins may wish to manage them, for example to set up access control or
resource quotas.
To list all namespaces
kubectl get ns
You can learn more about a namespace using the
describe
verb, for example:
kubectl describe ns default
Let’s now create a new namespace called
test
now:
kubectl get ns
To launch a pod in the newly created namespace
test
, do:
kubectl create --namespace=test -f https://raw.githubusercontent.com/mhausenblas/kbe/master/specs/ns/pod.yaml
Note that using above method the namespace becomes a
runtime property, that is, you can easily deploy the same pod or service, or
RC, etc. into multiple namespaces (for example:
dev
and prod
). If you however prefer to hard-code the namespace, you can
define it directly in the metadata
like so:
apiVersion: v1
kind: Pod
metadata:
name: podintest
namespace: test
To list namespaced objects such as our pod
podintest
, run following command as:
kubectl get pods --namespace=test
You can remove the namespace (and everything inside)
with:
kubectl delete ns test
<< Previous
No comments:
Post a Comment