Estimating the number of pods your OKD nodes can hold

    The cluster capacity tool simulates a sequence of scheduling decisions to determine how many instances of an input pod can be scheduled on the cluster before it is exhausted of resources to provide a more accurate estimation.

    You can run the cluster capacity analysis tool as a stand-alone utility from the command line, or as a job in a pod inside an OKD cluster. Running it as job inside of a pod enables you to run it multiple times without intervention.

    You can run the OKD cluster capacity tool from the command line to estimate the number of pods that can be scheduled onto your cluster.

    Prerequisites

    • Run the OpenShift Cluster Capacity Tool, which is available as a container image from the Red Hat Ecosystem Catalog.

    • Create a sample spec file, which the tool uses for estimating resource usage. The podspec specifies its resource requirements as limits or requests. The cluster capacity tool takes the pod’s resource requirements into account for its estimation analysis.

      An example of the Pod spec input is:

    Procedure

    1. From the terminal, log in to the Red Hat Registry:

      1. $ podman login registry.redhat.io
    2. Pull the cluster capacity tool image:

      1. $ podman pull registry.redhat.io/openshift4/ose-cluster-capacity
    3. Run the cluster capacity tool:

      1. $ podman run -v $HOME/.kube:/kube:Z -v $(pwd):/cc:Z ose-cluster-capacity \
      2. /bin/cluster-capacity --kubeconfig /kube/config --podspec /cc/pod-spec.yaml \
      3. --verbose (1)

      Example output

      1. small-pod pod requirements:
      2. - CPU: 150m
      3. - Memory: 100Mi
      4. The cluster can schedule 88 instance(s) of the pod small-pod.
      5. Termination reason: Unschedulable: 0/5 nodes are available: 2 Insufficient cpu,
      6. 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't
      7. tolerate.
      8. Pod distribution among nodes:
      9. small-pod
      10. - 192.168.124.214: 45 instance(s)
      11. - 192.168.124.120: 43 instance(s)

      In the above example, the number of estimated pods that can be scheduled onto the cluster is 88.

    Running the cluster capacity tool as a job inside of a pod has the advantage of being able to be run multiple times without needing user intervention. Running the cluster capacity tool as a job involves using a ConfigMap object.

    Prerequisites

    Download and install the cluster capacity tool.

    Procedure

    To run the cluster capacity tool:

    1. Example output

      1. kind: ClusterRole
      2. apiVersion: rbac.authorization.k8s.io/v1
      3. metadata:
      4. name: cluster-capacity-role
      5. rules:
      6. - apiGroups: [""]
      7. resources: ["pods", "nodes", "persistentvolumeclaims", "persistentvolumes", "services", "replicationcontrollers"]
      8. verbs: ["get", "watch", "list"]
      9. - apiGroups: ["apps"]
      10. resources: ["replicasets", "statefulsets"]
      11. verbs: ["get", "watch", "list"]
      12. - apiGroups: ["policy"]
      13. verbs: ["get", "watch", "list"]
      14. - apiGroups: ["storage.k8s.io"]
      15. verbs: ["get", "watch", "list"]
      16. EOF
    2. Create the service account:

      1. $ oc create sa cluster-capacity-sa
    3. Add the role to the service account:

      1. $ oc adm policy add-cluster-role-to-user cluster-capacity-role \
      2. system:serviceaccount:default:cluster-capacity-sa
    4. Define and create the Pod spec:

      1. apiVersion: v1
      2. kind: Pod
      3. metadata:
      4. name: small-pod
      5. labels:
      6. app: guestbook
      7. tier: frontend
      8. spec:
      9. containers:
      10. - name: php-redis
      11. image: gcr.io/google-samples/gb-frontend:v4
      12. imagePullPolicy: Always
      13. resources:
      14. limits:
      15. cpu: 150m
      16. memory: 100Mi
      17. requests:
      18. cpu: 150m
      19. memory: 100Mi
    5. The cluster capacity analysis is mounted in a volume using a ConfigMap object named cluster-capacity-configmap to mount input pod spec file pod.yaml into a volume test-volume at the path /test-pod.

      If you haven’t created a ConfigMap object, create one before creating the job:

    6. Create the job using the below example of a job specification file:

      1. apiVersion: batch/v1
      2. kind: Job
      3. metadata:
      4. name: cluster-capacity-job
      5. spec:
      6. parallelism: 1
      7. completions: 1
      8. template:
      9. spec:
      10. containers:
      11. - name: cluster-capacity
      12. image: openshift/origin-cluster-capacity
      13. imagePullPolicy: "Always"
      14. volumeMounts:
      15. - mountPath: /test-pod
      16. name: test-volume
      17. env:
      18. - name: CC_INCLUSTER (1)
      19. value: "true"
      20. command:
      21. - "/bin/sh"
      22. - "-ec"
      23. - |
      24. /bin/cluster-capacity --podspec=/test-pod/pod.yaml --verbose
      25. restartPolicy: "Never"
      26. serviceAccountName: cluster-capacity-sa
      27. volumes:
      28. - name: test-volume
      29. configMap:
      30. name: cluster-capacity-configmap
    7. Run the cluster capacity image as a job in a pod:

      1. $ oc create -f cluster-capacity-job.yaml
    8. Check the job logs to find the number of pods that can be scheduled in the cluster:

      1. $ oc logs jobs/cluster-capacity-job

      Example output

      1. small-pod pod requirements:
      2. - CPU: 150m
      3. - Memory: 100Mi
      4. The cluster can schedule 52 instance(s) of the pod small-pod.
      5. Termination reason: Unschedulable: No nodes are available that match all of the
      6. following predicates:: Insufficient cpu (2).
      7. Pod distribution among nodes:
      8. small-pod
      9. - 192.168.124.214: 26 instance(s)