• About Us
  • Privacy & Policy
HowTo's
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
HowTo's
No Result
View All Result
Home Kubernetes

Updating Kubernetes Labels with kubectl label

June 26, 2024
in Kubernetes, Kubernetes Commands Examples, Kubernetes Commands Tutorial, Kubernetes Tutorial
A A
0
12
SHARES
108
VIEWS
Share on FacebookShare on Twitter

The kubectl label command in Kubernetes is used to update the labels on resources within the cluster. Labels are key-value pairs attached to Kubernetes objects such as pods, services, and deployments, enabling easier identification and management of these resources.

Example 1: Label a Pod
To add a label “env=prod” to a pod named “nginx”:

kubectl label pod nginx env=prod

This command assigns the label “env=prod” to the pod named “nginx”.

Verification Steps: To verify, use:

kubectl get pod nginx --show-labels

Output should show the pod’s details including the labels.

Example 2: Update Labels of a Service
Modify labels of a service named “frontend” by adding “tier=frontend”:

kubectl label service frontend tier=frontend --overwrite

The --overwrite flag updates the label “tier” to “frontend” for the service.

Verification Steps: Verify the labels with:

kubectl get svc frontend --show-labels

Check if “tier=frontend” appears among the service’s labels.

Example 3: Remove a Label from Deployment
Remove the label “env” from a deployment named “webapp”:

kubectl label deployment webapp env-

The label “env” is removed from the “webapp” deployment.

Verification Steps: Confirm the label removal with:

kubectl get deployment webapp --show-labels

Ensure the label “env” no longer appears.

Example 4: Label Nodes
Add label “special=true” to a node named “node-1”:

kubectl label node node-1 special=true

This assigns the label “special=true” to the specified node.

Verification Steps: Check the node’s labels using:

kubectl get node node-1 --show-labels

Verify if “special=true” is listed under the node’s labels.

Example 5: Label Namespace
Label the namespace “development” with “environment=dev”:

kubectl label namespace development environment=dev

This command labels the namespace “development” for easier organization.

Verification Steps: Ensure the label is applied with:

kubectl get namespace development --show-labels

Confirm if “environment=dev” is displayed for the namespace.

Example 6: Label PersistentVolume
Label a PersistentVolume named “pv-1” with “type=ssd”:

kubectl label pv pv-1 type=ssd

This assigns the label “type=ssd” to the PersistentVolume “pv-1”.

Verification Steps: Check the labels with:

kubectl get pv pv-1 --show-labels

Ensure “type=ssd” is listed under the PersistentVolume’s labels.

Example 7: Labeling Deployments with Multiple Labels
Add multiple labels to a deployment named “api”:

kubectl label deployment api app=api environment=production

This command adds labels “app=api” and “environment=production” to the deployment.

Verification Steps: Verify the labels applied with:

kubectl get deployment api --show-labels

Check if both labels appear in the deployment’s label list.

Example 8: Labeling Service Account
Label a service account named “default” with “team=frontend”:

kubectl label serviceaccount default team=frontend

This assigns the label “team=frontend” to the service account “default”.

Verification Steps: Confirm the label addition with:

kubectl get serviceaccount default --show-labels

Ensure “team=frontend” is among the service account’s labels.

Example 9: Labeling StatefulSet
Label a StatefulSet named “mysql” with “app=mysql”:

kubectl label statefulset mysql app=mysql

This assigns the label “app=mysql” to the StatefulSet “mysql”.

Verification Steps: Check the labels with:

kubectl get statefulset mysql --show-labels

Ensure “app=mysql” is listed under the StatefulSet’s labels.

Example 10: Labeling Ingress
Add a label “app=nginx-ingress” to an Ingress named “nginx-ingress”:

kubectl label ingress nginx-ingress app=nginx-ingress

This assigns the label “app=nginx-ingress” to the Ingress resource.

Verification Steps: Verify the label with:

kubectl get ingress nginx-ingress --show-labels

Check if “app=nginx-ingress” appears in the Ingress’s labels.

Also check similar articles.

Building Kubernetes Customizations with kubectl kustomize
Waiting for Kubernetes Resources with kubectl wait
Replace Kubernetes Resources with kubectl replace
Patching Kubernetes Resources with kubectl patch
Applying Kubernetes Configurations with kubectl apply

Tags: KubernetesKubernetes Commands ExamplesKubernetes Commands TutorialKubernetes Tutorial
Previous Post

Building Kubernetes Customizations with kubectl kustomize

Next Post

Managing Kubernetes Annotations with kubectl annotate

Related You may like!

howto

Interacting with Kubernetes Plugins using kubectl plugin

June 26, 2024
howto

Configuring kubectl and kubeconfig Files

June 26, 2024

Exploring Kubernetes API Versions with kubectl api-versions

June 26, 2024

Understanding Kubernetes API Resources with kubectl api-resources

June 26, 2024

Generating Shell Completion Code with kubectl completion

June 26, 2024

Managing Kubernetes Annotations with kubectl annotate

June 26, 2024
Next Post
howto

Managing Kubernetes Annotations with kubectl annotate

howto

Generating Shell Completion Code with kubectl completion

howto

Understanding Kubernetes API Resources with kubectl api-resources

Discussion about this post

Latest Updated

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024
howto

Find Files by Group Name with -group in find Command

August 21, 2024
howto

Locate Files by Group ID Using -gid in find Command

August 21, 2024
howto

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Trending in Week

  • howto

    Using BTRFS Subvolume for User Home Directory in Linux

    22 shares
    Share 9 Tweet 6
  • Downloading Docker Images from a Registry

    13 shares
    Share 5 Tweet 3
  • Configuring SSL Connection Mode in mysqldump

    17 shares
    Share 7 Tweet 4
  • Omit Tablespace Information in mysqldump Output

    13 shares
    Share 5 Tweet 3
  • Setting MySQL Dump Compatibility Mode

    18 shares
    Share 7 Tweet 5
  • Setting Network Buffer Length in mysqldump

    13 shares
    Share 5 Tweet 3
  • Logging out from Docker Registries

    13 shares
    Share 5 Tweet 3
  • Scheduling Nodes in Kubernetes with kubectl uncordon

    12 shares
    Share 5 Tweet 3
  • Managing Default User Creation Settings in Linux

    15 shares
    Share 6 Tweet 4
  • Using Extended INSERT Syntax in mysqldump

    12 shares
    Share 5 Tweet 3
  • About Us
  • Privacy & Policy

© 2024 All Rights Reserved. Howto.swebtools.com.

No Result
View All Result

© 2024 All Rights Reserved. Howto.swebtools.com.