Labels & Selectors
Labels – Labels are key-value pairs attached to pods, ReplicaSet & Services. They are used for identifying objects for pods and ReplicaSet. It can be added at the creation time or can be modified or added at the run time.
Some properties –
- must be 63 characters or less (can be empty),
- unless empty, must begin and end with an alphanumeric character (
- could contain dashes (“), underscores (
_), dots (
.), and alphanumeric between.
Selectors – Kubernetes API currently supports two type of selectors −
- Equality-based selectors – We use = == != as equality selector.
environment = production tier != frontend
- Set-based selectors – It allows filtering of object in a set of values. There are three king of operator allowed in notin exists.
environment in (production, qa) tier notin (frontend, backend) partition !partition
Deleting an object isn’t as simple as it looks because it involves a lot of conditional checks about the used resources. Finalizers are certain conditions be met before an object can be deleted.
When you run
kubectl delete namespace/example k8s check the finalizers defined on that object.
- Issue a deletion command. – Kubernetes marks the object as pending deletion. This leaves the resource in the read-only “Terminating” state.
- Run each of the actions associated with the object’s Finalizers. – Each time a Finalizer action completes, that Finalizer is detached from the object, so it’ll no longer appear in the
- Kubernetes keeps monitoring the Finalizers attached to the object. – The object will be deleted once the
metadata.finalizersfield is empty, because all Finalizers were removed by the completion of their actions.