Home > Software engineering >  In Kubernetes how can I have a hard minimum number of pods for Deployment?
In Kubernetes how can I have a hard minimum number of pods for Deployment?

Time:09-22

On my deployment I can set replicas: 3 but then it only spins up one pod. Its my understanding that kubernetes will then fire up more pods as needed, up to three.

But for the sake of uptime I want to be able to have a minimum of three pods at all times and for it to maybe create more as needed but to never scale down lower than 3.

Is this possible with a Deployment?

CodePudding user response:

It is exactly as you did, you define 3 replicas in your Deployment.
Have you verified that you have enough resources for your Deployments?

Replicas example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3 # <------- The number of your desired replicas
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

K8S will spin up a new pod if it can do it meaning, if you have enough resources, the resources are valid (like nodes, selectors, image, volumes, configuration, and more)

If you have defined 3 replicas and you still getting only 1, examine your deployment or your events.

How to view events

# To view all the events (don't specify pod name or namespace)
kubectl get events

# Get event for specific pod
kubectl describe event <pod name> --namespace <namespace>

enter image description here

  • Related