DEV Community

Cover image for Kubernetes in practice
Mansoor Ahmed
Mansoor Ahmed

Posted on

Kubernetes in practice

Kubernetes provide us annotation feature with labels.
Annotations are basically words that explanations or comments on something.
For example, annotation can be used to write creator’s name or contact or about application it running.
Labels are meant to hold limited information whereas we can have larger annotation with any resource.
Annotations are way to add some extra information to the resource but it cannot be used to group or filter like labels.
Overlapping Labels
With labels it is easy is to group resources.
But what if any label overlap, for example
type = frontend is assigned to few pods with app_name_web and env_development
type = frontend is assigned to few pods with app_name_web and env_development
Name of particular resource will always be unique, what about setting the similar environment as production with in development, QA phase.
But what about times when you wan to split objects in separate, non-overlapping groups? We may want to only operate inside one group at a time.
Kubernetes also groups objects into namespaces.
Namespace is kind of virtual box which isolate self contain resources with other namespace.
We can easily separate the scope of resources using namespaces.e.g Resource in namespace for development phase cannot harm resources in namespace for production.
Similarly we can split them into multiple namespaces, which also allows us to use the same resource names multiple times (across different namespaces)
Creating namespace
Kubectl create namespace production
Kubectl get ns
Kubectl create ns development
Kubectl get ns
Pod inside namespace
nano myfirstpod.yaml
Kubectl create -f myfirstpod.yaml
Kubectl get pods –namespace = production
Kubectl run nsexample –image = ahmedmansoor/helloworld –port = 80 –restart = Never –namespace = development
Kubectl get pods
Kubectl get pods -n production
Kubectl get pods -n development
Listing pod from All Namespaces
Kubectl get pods — all-namespaces
Deleting Resource
Kubectl delete pod myfirstpod
Kubectl get pods –all-namespaces
Kubectl delete pod myfirstpod –namespace = production
Kubectl delete ns development
kubectl get ns
Kubectl get pod — show-labels
Kubectl delete pods-l type = backend
Kubectl delete pod –all
Replica Sets
Replica set is also one of the resource in Kubernetes like pods and others are.It is often used to guarantee the availability of a specified number of identical Pods.
Replica set is the resource that help creating and managing multiple copies of application (replicas) in Kubernetes.
When we create any pod through Replica set it ensures its pods are always kept running.
If the pod removes for any reason, such as
if the worker node disappears from the cluster
If the pod was evicted from the worker node
The replica set notes the missing pod and creates a replacement pod.
For more details visit:

Discussion (0)