Openshift v3 pod bulk creation with Amazon Elastic Block Store (EBS) – Block Storage as persistent storage

If you ever want to create many Openshift pods with one EBS volume attached to each pod then can help you with that. Help is showed below.
There are few steps which has to be taken in advance before running script

  • It is necessary to configure openshift nodes / masters to be able to talk with Amazon EC2. This blog post can give you some ideas what to do to achieve this aws-ebs-as-persistent-storage-for-openshift
  • boto3 has to be installed on machine where is supposed to run pip install boto3 will get it
  • Ensure to run
    # pip install awscli 
    # aws configure 
  • and follow steps to configure Amazon cli client. aws configure is going to ask questions regarding aws credentials which needs to be provided

    After all above is satisfied, running below

     ./ --volumesize=1 --image=fedora  --tagprefix=fedora_test --minpod=1 --maxpod=11 --pvfile=pv.json --pvcfile=pvc.json --podfile=pod.json 

    will create 10 pods based on image fedora, with each pod having mounted one EBS volume to /mnt/persistentvolume. Each EBS volume will have tag value of fedora_test. The EBS tag is not used for anything except to easier delete EBS volumes later on, for example using script from delete-ebs-volumes-based-on-ebs-volume-tag

    pv.json, pvc.json, pod.json are generic files which examples can be found here

    #python -h
    usage: [-h] [--volumesize VOLUMESIZE] [--vtype VTYPE]
                               [--region REGION] [--image IMAGE]
                               [--tagprefix TAGPREFIX] [--mountpoint MOUNTPOINT]
                               [--minpod MINPOD] [--action ACTION] --maxpod MAXPOD
                               --pvfile PVFILE --pvcfile PVCFILE --podfile PODFILE
    Script to create OSE pods and attach one EBS volume per pod as persistent
    optional arguments:
      -h, --help            show this help message and exit
      --volumesize VOLUMESIZE
                            size of EBS voluems - in GB
      --vtype VTYPE         EBS volume type, default is gp2
      --region REGION       Amazon region where to connect
      --image IMAGE         docker image to use
      --tagprefix TAGPREFIX
                            tag prefix for EBS volumes, default tag is openshift-
      --mountpoint MOUNTPOINT
                            mount point inside pod where EBS volume will be
                            mounted, default is /mnt/persistentvolume
      --minpod MINPOD       minimum number of pods to create - default is 1 - so
                            minimum one pod will be created
      --action ACTION       what to do - either to create pods or delete pods
      --maxpod MAXPOD       maximum number of pods to create - required parameter
      --pvfile PVFILE       persistent volume definition json file - required
      --pvcfile PVCFILE     persistent volume claim definition json file -
                            required parameter
      --podfile PODFILE     pod definition json file - required parameter

    #amazon, #aws, #ebs, #linux, #openshift, #python