Organizing Pods and other Resources using Namespaces and Labels
Namespaces and Labels
Organizing objects into Namespaces
Namespaces in Kubernetes help organize Kubernetes API objects into non-overlapping groups.
Namespaces divide a single physical kubernetes cluster into many virtual clusters.
Listing namespaces and the objects they obtain.
Namespaces prefixed with kube- are reserved for kubernetes system namespaces.
Listing objects in a specific namespace
Listing objects across all namespaces
Creating namespaces
Creating a namespace from a manifest file.
To execute the manifest file :
To get all namespaces :
Creating objects in a specific namespace
Making Kubectl default to a different namespace
To switch to a different namespace, you must update the current context.
Organizing Pods with Labels
A canary release is a deployment pattern where you deploy a new version of an application alongside the stable version, and direct only a small portion of requests to the new version to see how it behaves before rolling it out to all users. This prevents a bad release from being made available to too many users.
Introducing Labels
-Labels are used to organize kubernetes api objects.
-
A label is a key value pair you attach to an object that allows any user of the cluster to identify the object's role in the system.
-
Both the key and value are simple strings that you can specify as you wish.
-
An object can have more than one label, but the label keys must be unique within that object.
Using labels to provide additional information about an object.
We can use labels to distinguish between the type of the release.
To help indentify the application and the release running in each pod, we use pod labels.
Kubernetes does not care what labels you add to your objects. You can choose the keys and value however you want.
Adding Labels to Pods
Creating a namespace :
Configuring kubernetes to use the new namespace :
Defining labels in Object Manifest
Labels are supported by all object kinds. You specify them in the metadata.labels map.
Displaying pods with label names :
Deleting objects using a label selector