Score:1

what is the difference between 'metadata.labels' and 'spec.template.metadata.labels'

cn flag

reading the kubernetes docs, it is not very clear to me what is the difference between specifying labels at the top-level metadata key, versus at the spec level.

Consider:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: nginx
  name: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      run: nginx
  strategy: {}
  template:
    metadata:
      labels:
        run: nginxv1
    spec:
      containers:
      - image: nginx
        name: nginx

which I have copied from https://stackoverflow.com/questions/54837981/k8s-significance-of-spec-template-metadata-section , where my google searching landed me.

What's the difference between the two labels that are set in this manifest?

Score:0
pt flag

metadata.labels sets the labels that apply to the deployment.

spec.template.metadata.labels sets the labels that apply to pods management by the deployment.

The values in spec.selectors.matchLabels are used to select pods, so they need to match the labels in spec.template.metadata.labels; they have nothing to do with the Deployment's metadata.labels.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.