部署创建了哪些 Pod?

时间:2021-06-29 06:50:07

标签: kubernetes

我的 kind: Deployment 文件中有两个 yaml 主要的

apiVersion: apps/v1
kind: Deployment
metadata:
  name: accounts-management-service
  labels:
    app: accounts-management-service
spec:
  replicas: $($env:WEB_REPLICAS)
  selector:
    matchLabels:
      app: accounts-management-service
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 20%
      maxUnavailable: 10%
  progressDeadlineSeconds: 3600
  template:
    metadata:
      labels:
        app: accounts-management-service
    spec:
      containers:
        - image: registry$(GetHash).azurecr.io/$(GetContext 'ApplicationContainerName')
          name: accounts-management-service
          command: ["npm"]
          args: ["run", "start:production:web"]
          resources:
            requests:
              memory: "500Mi"
              cpu: "1000m"
            limits:
              memory: "4096Mi"
              cpu: "1001m"
          env:
            - name: CONFIG_DEPLOYMENT_UNIT
              value: $(GetContext 'DeploymentUnit')
            - name: NODE_ENV
              value: $(GetContext 'DeploymentUnit')
            - name: TENANT
              value: "$(GetContext 'DeploymentUnit' | Format -NoHyphens)$(GetContext 'Cluster')"
            - name: ROLE
              value: $(GetContext 'Cluster')
          ports:
            - containerPort: 1337
              protocol: TCP
          volumeMounts:
            - name: secret-agent
              mountPath: /var/run/secret-agent
          readinessProbe:
            httpGet:
              path: /v0.1/status
              port: 1337
            successThreshold: 2
            failureThreshold: 3
            initialDelaySeconds: 60
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /v0.1/status_without_db
              port: 1337
            failureThreshold: 3
            initialDelaySeconds: 60
            periodSeconds: 30
      volumes:
        - name: secret-agent
          hostPath:
            path: /var/run/secret-agent
            type: DirectoryOrCreate

第二个

# second
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: accounts-management-service-second
  labels:
    app: accounts-management-service-second
spec:
  replicas: $($env:second_REPLICAS)
  selector:
    matchLabels:
      app: accounts-management-service-second
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 10%
      maxUnavailable: 10%
  template:
    metadata:
      labels:
        app: accounts-management-service-second
    spec:
      containers:
        - image: registry$(GetHash).azurecr.io/$(GetContext 'ApplicationContainerName')
          name: accounts-management-service-second
          command: ["npm"]
          args: ["run", "start:production:second"]
          resources:
            requests:
              memory: "500Mi"
              cpu: "250m"
            limits:
              memory: "8192Mi"
              cpu: "1001m"
          env:
            - name: CONFIG_DEPLOYMENT_UNIT
              value: $(GetContext 'DeploymentUnit')
            - name: NODE_ENV
              value: $(GetContext 'DeploymentUnit')
            - name: TENANT
              value: "$(GetContext 'DeploymentUnit' | Format -NoHyphens)$(GetContext 'Cluster')"
            - name: ROLE
              value: $(GetContext 'Cluster')
          ports:
            - containerPort: 1337
              protocol: TCP
          volumeMounts:
            - name: secret-agent
              mountPath: /var/run/secret-agent
          readinessProbe:
            httpGet:
              path: /status
              port: 1337
            initialDelaySeconds: 60
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /status
              port: 1337
            initialDelaySeconds: 60
            periodSeconds: 10
      volumes:
        - name: secret-agent
          hostPath:
            path: /var/run/secret-agent
            type: DirectoryOrCreate

它们都指向相同的卷路径。我是 Kubernetes 的新手,我试图了解 pod 创建与两个 kind: Deployment 之间的关系。如果有人能解释一下,那就太好了。我希望这属于 SO 允许的问题类别。

3 个答案:

答案 0 :(得分:1)

基本上,部署通过部署规范部分和 .spec.template.spec 部分中定义的标签找出他们正在管理的 Pod。

部署检查与提供的标签匹配的正在运行的 pod,同时确定可用副本数是否是所需的副本数。

如果需要计数 > 可用计数,DeploymentController 基于模板部分创建一个新的 Pod(实际上,部署控制一个 ReplicaSet,它反过来控制 Pod,但这是您理解不需要的额外知识)。然而,部署不仅仅基于模板创建和删除 Pod。如果部署所在的命名空间中已经有 Pod 运行,且这些 Pod 与部署中指定的标签相匹配,则会将此 Pod 视为部署的一部分并计入可用副本。

希望这能让您对部署有所了解。

答案 1 :(得分:1)

如果您想找出指定部署创建了哪些 pod,您可以使用带有 kubectl get pods 选项的 --selector 命令来过滤这些 pod。

您在部署模板中定义的标签是 app=accounts-management-serviceapp=accounts-management-service-second,您可以通过以下方式找出这些 Pod:

$ kubectl get pods --selector=app=accounts-management-service
$ kubectl get pods --selector=app=accounts-management-service-second

答案 2 :(得分:1)

部署管理的副本数基本上适用于任何配置的工作负载。

后台部署使用 ReplicasetsReplicationController

因此,如果在部署中您拥有所需的副本 1,它将由部署管理。

如果扩展到位,部署会持续检查所需副本和可扩展副本。

建议在部署之上实现扩展,扩展HPA会通知部署将副本扩展到3-4

<块引用>

您在 Deployment 中描述了所需的状态,并且 Deployment 控制器在某个时间将实际状态更改为所需状态 控制率。您可以定义部署来创建新的副本集, 或删除现有部署并采用其所有资源 新部署。

同样在部署中,如果您正在更新 POD 或容器,则您可以为更新配置策略,因此理想情况下,它们会一个一个地关闭,一个新的出现。

因此在此过程中发生的停机时间更少,此策略在部署级别进行管理和配置。

示例

strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 20%
      maxUnavailable: 10%

此外,两次部署意味着在 YAML 中配置了两种不同类型的应用程序或微服务或工作负载。每个微服务配置一个。

如果您有任何问题,请随时在评论中添加问题。