<p>I am looking for how to have a spare/cold replica/pod in my Kubernetes configuration.  I assume it would go in my Kuberentes deployment or HPA configuration.  Any idea how I would make it so I have 2 spare/cold instances of my app always ready, but only get put into the active pods once HPA requests another instance?  My goal is to have basically zero startup time on a new pod when HPA says it needs another instance.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: someName
  namespace: someNamespace
  labels:
    app: someName
    version: &quot;someVersion&quot;
spec:
  replicas: $REPLICAS
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: someMaxSurge
      maxUnavailable: someMaxUnavailable
  selector:
    matchLabels:
      app: someName
      version: someVersion
  template:
    metadata:
      labels:
        app: someName
        version: &quot;someVersion&quot;
    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: &quot;someVersion&quot;       
---
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
</code></pre>

Brian
<blockquote>
<p>I am just wanting to always have 2 spare for scaling, or if one becomes unavailable or any reason</p>
</blockquote>
<p>It is a good practice to have at least two replicas for services on Kubernetes. This helps if e.g. a node goes down or you need to do <a href="https://kubernetes.io/docs/concepts/workloads/pods/disruptions/" rel="nofollow noreferrer">maintenance of the node</a>. Also set <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/" rel="nofollow noreferrer">Pod Topology Spread Constraints</a> so that those pods are scheduled to run on different nodes.</p>
<p>Set the number of replicas that you minimum want as desired state. In Kubernetes, traffic will be load balanced to the replicas. Also use <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">Horizontal Pod Autoscaler</a> to define when you want to autoscale to more replicas. You can set the requirements low for autoscaling, if you want to scale up early.</p>
