首页 > 解决方案 > k8s 如何关联 ReplicaSet 和 Pod?

问题描述

假设我有以下 k8s 配置文件,其中包含 2 个相同的部署,只是名称不同。

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

据我了解,k8s 通过标签关联 ReplicaSet 和 Pod。因此,有了上面的配置,我猜会有一些问题或者k8s会禁止这个配置。然而,事实证明一切都很好。除了标签之外,k8s 还有其他东西用来关联 ReplicaSet 和 Pod 吗?

标签: kubernetes

解决方案


推荐阅读