Pods without Labels:
As per below image, we are running multiple microservices with multiple replicas and multiple releases without Pod labels. It is evident that we need to find a way to organize the Pods into smaller groups based on arbitrary criteria. Here, Pod Labels help us to organizing Pods into different groups.Pods with Labels:
As per below image, we are running multiple microservices with multiple replicas and multiple releases with Pod labels. Each Pod is labeled with two labels
As per below image, we are running multiple microservices with multiple replicas and multiple releases with Pod labels. Each Pod is labeled with two labels
- app, it specifies Pod belongs to which app, component, or service
- release, it specifies Pod running under stable, beta or a canary release
Labels
Label is a key-value pair which is attached to pods, deployments, etc.
- It acts an identifier on K8 object (Ex: Pod or Deployment). So, the other Kubernetes objects (Ex: Service, DaemonSet) can communicate by matching same label names.
- It can be attached to Kubernetes objects at creation time or directly on live objects by using Imperative way
- Same label key/value can be assigned to multiple Kubernetes objects
- Each object in the label can have set of key/value and each key must be unique for a given object
- Label key should not exceed 63 characters and allowed characters are alphanumeric, dash(-), underscore(_), dot(.)
- Label value should not exceed 63 characters and allowed characters are alphanumeric, dash(-), underscore(_), dot(.)
metadata:
name: pod-label-demo
labels:
release: stable
app: ui
Example: Creating labels on Pod
apiVersion: v1
kind: Pod
metadata:
name: pod-label-demo
labels:
release: stable
app: ui
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
There are two labels i.e. app: ui, release: stable are assigned to Pod
// show all labels on each Pod
> kubectl get pods --show-labels
// show all labels on each Deployment
> kubectl get deployments --show-labels
// show all Pods where label app: ui
> Kubectl get pods -l app=ui
// add label to running Pod
// syntax
kubectl label Pod <podname> <key>=<value>
// example
> kubectl label Pod pod-label-demo release=stable
// delete Pods using label
> kubectl delete pod -l app=ui
Kubernetes for Developers Journey.
- Kubernetes for Developers #25: PersistentVolume and PersistentVolumeClaim in-detail
- Kubernetes for Developers #24: Kubernetes Volume hostPath in-detail
- Kubernetes for Developers #23: Kubernetes Volume emptyDir in-detail
- Kubernetes for Developers #22: Access to Multiple Clusters or Namespaces using kubectl and kubeconfig
- Kubernetes for Developers #21: Kubernetes Namespace in-detail
- Kubernetes for Developers #20: Create Automated Tasks using Jobs and CronJobs
- Kubernetes for Developers #19: Manage app credentials using Kubernetes Secrets
- Kubernetes for Developers #18: Manage app settings using Kubernetes ConfigMap
- Kubernetes for Developers #17: Expose service using Kubernetes Ingress
- Kubernetes for Developers #16: Kubernetes Service Types - ClusterIP, NodePort, LoadBalancer and ExternalName
- Kubernetes for Developers #15: Kubernetes Service YAML manifest in-detail
- Kubernetes for Developers #14: Kubernetes Deployment YAML manifest in-detail
- Kubernetes for Developers #13: Effective way of using K8 Readiness Probe
- Kubernetes for Developers #12: Effective way of using K8 Liveness Probe
- Kubernetes for Developers #11: Pod Organization using Labels
- Kubernetes for Developers #10: Kubernetes Pod YAML manifest in-detail
- Kubernetes for Developers #9: Kubernetes Pod Lifecycle
- Kubernetes for Developers #8: Kubernetes Object Name, Labels, Selectors and Namespace
- Kubernetes for Developers #7: Imperative vs. Declarative Kubernetes Objects
- Kubernetes for Developers #6: Kubernetes Objects
- Kubernetes for Developers #5: Kubernetes Web UI Dashboard
- Kubernetes for Developers #4: Enable kubectl bash autocompletion
- Kubernetes for Developers #3: kubectl CLI
- Kubernetes for Developers #2: Kubernetes for Local Development
- Kubernetes for Developers #1: Kubernetes Architecture and Features
Happy Coding :)
No comments:
Post a Comment