How does k8s correlate ReplicaSet and Pods?

11/1/2021

Say I have the following k8s config file with 2 identical deployments only different by name.

kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    app: hello-world
  name: hello-world-deployment-1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
        - name: hello-world-2
          image: rancher/hello-world:v0.1.2
          resources:
            limits:
              cpu: "1"
              memory: 100M
---
kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    app: hello-world
  name: hello-world-deployment-2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
        - name: hello-world-2
          image: rancher/hello-world:v0.1.2
          resources:
            limits:
              cpu: "1"
              memory: 100M

As I understand, k8s correlate ReplicaSets and Pods by their label. Therefore, with the above configuration, I guess there will be some problem or k8s will forbid this configuration. However, it turns out everything is fine. Apart from the labels, are there something else k8s is using to correlate ReplicaSet and Pods?

-- san1127
kubernetes

0 Answers