首页 > 解决方案 > Kubernetes 备用/冷副本/Pod

问题描述

我正在寻找如何在我的 Kubernetes 配置中拥有备用/冷副本/pod。我假设它会出现在我的 Kuberentes 部署或 HPA 配置中。知道我将如何做到这一点,因此我的应用程序的 2 个备用/冷实例始终准备就绪,但只有在 HPA 请求另一个实例时才被放入活动 pod?我的目标是当 HPA 说它需要另一个实例时,新 pod 的启动时间基本上为零。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: someName
  namespace: someNamespace
  labels:
    app: someName
    version: "someVersion"
spec:
  replicas: $REPLICAS
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: someMaxSurge
      maxUnavailable: someMaxUnavailable
  selector:
    matchLabels:
      app: someName
      version: someVersion
  template:
    metadata:
      labels:
        app: someName
        version: "someVersion"
    spec:
      containers:
      - name: someName
        image: someImage:someVersion
        imagePullPolicy: Always
        resources:
          limits:
            memory: someMemory
            cpu: someCPU
          requests:
            memory: someMemory
            cpu: someCPU
        readinessProbe:
          failureThreshold: someFailureThreshold
          initialDelaySeconds: someInitialDelaySeconds
          periodSeconds: somePeriodSeconds
          timeoutSeconds: someTimeoutSeconds
        livenessProbe:
          httpGet:
            path: somePath
            port: somePort
          failureThreshold: someFailureThreshold
          initialDelaySeconds: someInitialDelay
          periodSeconds: somePeriodSeconds
          timeoutSeconds: someTimeoutSeocnds
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: someName
  namespace: someNamespace
spec:
  minAvailable: someMinAvailable
  selector:
    matchLabels:
      app: someName
      version: "someVersion"       
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: someName-hpa
  namespace: someNamespace
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: someName
  minReplicas: someMinReplicas
  maxReplicas: someMaxReplicas
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: someAverageUtilization

标签: kuberneteskubernetes-deploymentkubernetes-hpa

解决方案


我只是想总是有 2 个备用用于扩展,或者如果一个变得不可用或任何原因

在 Kubernetes 上至少有两个服务副本是一个很好的做法。如果某个节点出现故障或您需要维护该节点,这会有所帮助。还要设置Pod 拓扑传播约束,以便这些 pod 被安排在不同的节点上运行。

将所需的最低副本数设置为所需的状态。在 Kubernetes 中,流量将负载均衡到副本。还可以使用Horizo​​ntal Pod Autoscaler来定义何时要自动缩放到更多副本。如果您想尽早扩展,可以将自动扩展的要求设置得较低。


推荐阅读