Kubernetes 备件/冷副本/Pod

时间:2021-03-30 12:41:21

标签: kubernetes kubernetes-deployment kubernetes-hpa

我正在寻找如何在我的 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

1 个答案:

答案 0 :(得分:2)

<块引用>

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

在 Kubernetes 上至少有两个服务副本是一种很好的做法。这有帮助,例如一个节点出现故障或者您需要执行 maintenance of the node。还要设置 Pod Topology Spread Constraints,以便安排这些 Pod 在不同节点上运行。

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

相关问题