DevOps Classroom notes 08/Oct/2026

K8s Label

Labels and selectors offical docs

  • labels are key-value pairs attached to k8s object
  • metadata filterling by labels
  • it will works for = or == and != these operations will suppourted
---
apiVersion: v1
kind: Pod
metadata:
  name: apache2
  labels:
    app: apache
    tier: backend
    env: prod
spec:
  containers:
    - name: front-end-app
      image: httpd:latest
      ports:
        - containerPort: 80

---
apiVersion: v1
kind: Pod
metadata:
  name: frondend
  labels:
    app: apache
    tier: frondend
    env: prod
spec:
  containers:
    - name: front-end-app
      image: httpd:latest
      ports:
        - containerPort: 80
Kubectl get pods -l <label_key>=<label_value> -n <namespace>
kubectl get pods -l tier=frondend
kubectl get pods -l backend
kubectl get pods -l env=prod

Selectors:

  • selectors will work on opertaions In or NotIn
  • here it will suppourt key and multiple values.
selector:
  matchExpression:
    - key: tier
      operator: In
      values: 
        - frontend
        - backend
    - key: env
      operator: NotIn
      values: 
        - dev

Types of Selectors:

  1. Equality base selector:
  • matching resources where my label specified values
matchLabels:
  key: vlaue
selector:
  matchLabels:
    env: dev
    tier: frontend
  1. set-base selector
  • which suppourt operations In and NotIn
  1. Field selector:
  • it is used other than lables in metadata
metadata.name
metadata.namespace
metadata.app
Status.phase
spec.conatainer.name
kubectl get pods  --field-selector=Status.phase=Runing
kubectl get pods  --field-selector=metadata.name=frontend

combine:

  • fillter pods bases on label and filed selector
kubectl get pods -l tier=frondend --field-selector=Status.phase=Runing

Controller:

  • pod does n’t have a self healing option.
  • this controller will manage pods like create/delete or compare pods to make diserd state

Evolution for controller

pod --> Relipcation-controller (old way) --> replicas-set (new) --> Deployment (recommend)

Replication-controller:

Offical docs

  • it will works on equal base like key=value EX: app: web
  • = or == and !=
apiVersion: v1
kind: ReplicationController
metadata:
  name: nopcommerce-rc
  labels:
    app: nopcommerce
spec:
  replicas: 3
  selector:
    app: nopcommerce
  template:
    metadata:
      labels:
        app: nopcommerce
    spec:
      containers:
        - name: nopcommerce-container1
          image: httpd:latest
          ports:
            - containerPort: 5000
          resources:
            limits:
              memory: "512Mi"
              cpu: "500m"
            requests:
              memory: "256Mi"
              cpu: "250m"

Replicaset:

  • it will suppourt for both equal and setbase selectors
  • operations In and NotIn and mutiple values.
apiVersion: v1
kind: ReplicationController
metadata:
  name: nopcommerce-rc
  labels:
    app: nopcommerce
spec:
  replicas: 3
  selector:
    matchExpression:
        - key: tier
        operator: In
        values: 
            - frontend
            - backend
        - key: app
        operator: Not
        values: 
            - nopcommerce
  template:
    metadata:
      labels:
        app: nopcommerce
    spec:
      containers:
        - name: nopcommerce-container1
          image: httpd:latest
          ports:
            - containerPort: 5000
          resources:
            limits:
              memory: "512Mi"
              cpu: "500m"
            requests:
              memory: "256Mi"
              cpu: "250m"

Task:

  1. create replicaset and ReplicationController using api referances
  2. try to deploy and test pods and fillter label and selectors

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%