Kubernetes in practice

Kubernetes in practice


  • Kubernetes provide us annotation feature with labels.
  • Annotations are basically words that explanations or comment on something.
  • For example, annotation can be used to write the creator’s name or contact or about the application is running.
  • Labels are meant to hold limited information whereas we can have larger annotation with any resource.
  • Annotations are the way to add some extra information to the resource but they 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 a few pods with app_name_web and env_development
  • type = frontend is assigned to a few pods with app_name_web and env_development
  • The name of a particular resource will always be unique, what about setting a similar environment as production within the development, QA phase.
  • But what about times when you want to split objects into separate, non-overlapping groups? We may want to only operate inside one group at a time.


  • Kubernetes also groups objects into namespaces.
  • A namespace is a kind of virtual box that isolates self contain resources with another namespace.
  • We can easily separate the scope of resources using namespaces. e.g Resource in the namespace for the development phase cannot harm resources in the 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 my first pod. yaml
  • Kubectl creates -f my first pod. 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

  • A replica set is also one of the resources in Kubernetes like pods and others are. It is often used to guarantee the availability of a specified number of identical Pods.
  • A replica set is a resource that helps create and manage multiple copies of applications (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.
Mansoor Ahmed is Chemical Engineer, web developer, a writer currently living in Pakistan. My interests range from technology to web development. I am also interested in programming, writing, and reading.
Posts created 421

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top