replicas

Change the number of replicas for a resource.

Given this kubernetes Deployment fragment:

  1. kind: Deployment
  2. metadata:
  3. name: deployment-name
  4. spec:
  5. replicas: 3

one can change the number of replicas to 5 by adding the following to your kustomization:

  1. apiVersion: kustomize.config.k8s.io/v1beta1
  2. kind: Kustomization
  3. replicas:
  4. - name: deployment-name
  5. count: 5

This field accepts a list, so many resources can be modified at the same time.

As this declaration does not take in a kind: nor a group: it will match any group and kind that has a matching name and that is one of:

  • Deployment
  • ReplicationController
  • ReplicaSet
  • StatefulSet

For more complex use cases, revert to using a patch.

Example

Input File

  1. # deployment.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: the-deployment
  6. spec:
  7. replicas: 5
  8. template:
  9. containers:
  10. - name: the-container
  11. image: registry/conatiner:latest
  1. # kustomization.yaml
  2. apiVersion: kustomize.config.k8s.io/v1beta1
  3. kind: Kustomization
  4. replicas:
  5. - name: deployment-name
  6. count: 10
  7. resources:
  8. - deployment.yaml

Output

  1. # deployment.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: the-deployment
  6. spec:
  7. replicas: 10
  8. template:
  9. containers:
  10. - name: the-container
  11. image: registry/conatiner:latest