My Kubernetes Learning Notes: Image Pull Policy, Labels & Selectors

Hey folks! As I continue learning Kubernetes, I’ve been digging into some foundational concepts that I think are super important to understand early on — Image Pull Policies, Labels, and Selectors. Thought I'd share what I’ve learned so far in case it helps anyone else on the same path! Image Pull Policy in Kubernetes There are three options: Always This will always pull the image from the container registry (like Docker Hub), no matter what. It’s great if you're constantly updating the image and want to make sure the latest version is always used. IfNotPresent This will only pull the image if it’s not already available locally on the node. It seems to be the default for tagged images, and it is super useful when you’re trying to avoid unnecessary pulls. Never This one won’t pull the image at all. Kubernetes just uses whatever is already there on the node. It’s probably best for air-gapped or strictly controlled environments. Example of how I used it in a YAML file: apiVersion: v1 kind: Pod metadata: name: abc spec: containers: - name: nginx-pod image: nginx imagePullPolicy: IfNotPresent Labels in Kubernetes Labels are basically key-value pairs that we can attach to pods (or other Kubernetes objects). They’re really helpful for organizing, filtering, and managing resources. apiVersion: v1 kind: Pod metadata: name: nginx-pod labels: department: hr spec: containers: - name: nginx-container image: nginx Some commands I learned: kubectl get pods --show-labels # Show labels for all pods kubectl label pod = # Add a new label kubectl label pod - # Remove a label kubectl label --overwrite pod = # Overwrite an existing label Label Selectors — Equality & Set Based Selectors let you filter pods based on their labels, which is super handy when you have a lot of resources. Equality-Based Selectors These use = and != to match specific key/value pairs. kubectl get pods --selector department=it # Only pods with department=it kubectl get pods --selector department!=it # All pods except department=it kubectl get pods -l department=hr # Another way to filter by label Set-Based Selectors These are used when you want to filter by multiple values. kubectl get pods --selector 'department in (hr,prod)' # Pods with department=hr or department=prod These might seem like small details at first, but I'm starting to realize how powerful they are when managing pods and organizing deployments at scale. Still lots to learn, but this felt like a good checkpoint to share what I’ve picked up If you're also learning Kubernetes, I would love to hear what helped you wrap your head around these topics! Drop tips or corrections if I missed anything! If you're also learning Kubernetes, I would love to hear what helped you wrap your head around these topics! Drop tips or corrections if I missed anything! Feel free to connect: Hashnode - https://hashnode.com/@dechen-tshering-3577 LinkedIn - https://rb.gy/7w546x I’ll be posting more as I go!

Apr 20, 2025 - 16:43
 0
My Kubernetes Learning Notes: Image Pull Policy, Labels & Selectors

Hey folks!
As I continue learning Kubernetes, I’ve been digging into some foundational concepts that I think are super important to understand early on — Image Pull Policies, Labels, and Selectors.
Thought I'd share what I’ve learned so far in case it helps anyone else on the same path!

Image Pull Policy in Kubernetes

There are three options:

  1. Always

    This will always pull the image from the container registry (like Docker Hub), no matter what. It’s great if you're constantly updating the image and want to make sure the latest version is always used.

  2. IfNotPresent

    This will only pull the image if it’s not already available locally on the node. It seems to be the default for tagged images, and it is super useful when you’re trying to avoid unnecessary pulls.

  3. Never

    This one won’t pull the image at all. Kubernetes just uses whatever is already there on the node. It’s probably best for air-gapped or strictly controlled environments.

Example of how I used it in a YAML file:


apiVersion: v1
kind: Pod
metadata:
  name: abc
spec:
  containers:
  - name: nginx-pod
    image: nginx
    imagePullPolicy: IfNotPresent

Labels in Kubernetes

Labels are basically key-value pairs that we can attach to pods (or other Kubernetes objects). They’re really helpful for organizing, filtering, and managing resources.


apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    department: hr
spec:
  containers:
  - name: nginx-container
    image: nginx

Some commands I learned:

kubectl get pods --show-labels       # Show labels for all pods
kubectl label pod  =  # Add a new label
kubectl label pod  -         # Remove a label
kubectl label --overwrite pod  = # Overwrite an existing label

Label Selectors — Equality & Set Based

Selectors let you filter pods based on their labels, which is super handy when you have a lot of resources.

Equality-Based Selectors

These use = and != to match specific key/value pairs.


kubectl get pods --selector department=it   # Only pods with department=it
kubectl get pods --selector department!=it  # All pods except department=it
kubectl get pods -l department=hr           # Another way to filter by label

Set-Based Selectors

These are used when you want to filter by multiple values.



kubectl get pods --selector 'department in (hr,prod)'   # Pods with department=hr or department=prod

These might seem like small details at first, but I'm starting to realize how powerful they are when managing pods and organizing deployments at scale.

Still lots to learn, but this felt like a good checkpoint to share what I’ve picked up

If you're also learning Kubernetes, I would love to hear what helped you wrap your head around these topics! Drop tips or corrections if I missed anything!

If you're also learning Kubernetes, I would love to hear what helped you wrap your head around these topics! Drop tips or corrections if I missed anything!
Feel free to connect:
Hashnode - https://hashnode.com/@dechen-tshering-3577
LinkedIn - https://rb.gy/7w546x

I’ll be posting more as I go!