Updated on 2024-03-15 GMT+08:00

All Pods Have the app and version Labels

Description

All pods of a Service must be labeled with app and version. app traces traffic in traffic monitoring, and version distinguishes different versions in grayscale release. If a pod is not labeled with app or version, this item is abnormal.

Rectification Guide

The labels of pods are configured in spec.template.metadata.labels of the Deployment. The recommended configuration is as follows:

labels:
  app: {serviceName}
  version: v1

Modifying or deleting the Deployment will trigger pod rolling upgrade, which may cause temporary service interruption. Therefore, perform the operation at a proper time.

  1. Copy the original workload configuration and save it as a YAML file.

    kubectl get deployment {deploymentName} -n {namespace} -o yaml > {deploymentName}-deployment.yaml

    For example:

    kubectl get deployment productpage -n default -o yaml > productpage-deployment.yaml

  2. Modify the productpage-deployment.yaml file. If the file does not contain app and version, add them. You are advised to set app to the Service name and the version to v1.
  3. Delete the original workload.

    kubectl delete deployment {oldDeploymentName} -n {namespace}

  4. Apply the new workload configuration.

    kubectl apply -f productpage-deployment.yaml

For clusters of v1.15 or earlier, you can modify pod labels on the CCE console, but residual ReplicaSets may exist.

To check whether there are residual ReplicaSets, perform the following steps:

  1. Query the ReplicaSets of the Deployment.

    kubectl get replicaset | grep {deploymentName}

  2. Find the ReplicaSets containing more than one pod. These ReplicaSets may be residual after label modification. You need to delete the old ReplicaSets.

    kubectl delete replicaset {replicaSetName} -n {namespace}