Script for creating EBS persistent volumes in OpenShift/Kubernetes

If you aren't using the automated dynamic volume provisioning (which you should!). Here is a short bash script to help you automatically create both the EBS volume and Kubernetes persistent volume:


if [ $# -ne 2 ]; then  
    echo "Usage: sh SIZE COUNT"

for i in `seq 1 $2`; do  
  vol=$(ec2-create-volume --size $size --region ap-southeast-2 --availability-zone ap-southeast-2a --type gp2 --encrypted | awk '{print $2}')

  echo "
  apiVersion: v1
  kind: PersistentVolume
    labels: ap-southeast-2 ap-southeast-2a
    name: pv-$vol
      storage: $size
      - ReadWriteOnce
      fsType: ext4
      volumeID: aws://ap-southeast-2a/$vol
    persistentVolumeReclaimPolicy: Delete" | oc create -f -

WordPress editor missing when using CloudFront

We often put CloudFront in front of our WordPress sites to increase the load times of the website significantly.

CloudFront and WordPress have a few quirks, the main one will be the missing rich post/page editor that suddenly goes missing from your wp-admin.

The issue comes down to the UA sniffing that WordPress does.

Adding this into your functions.php will be a good quick fix for you

* Ignore UA Sniffing and override the user_can_richedit function
* and just check the user preferences
* @return bool
function user_can_richedit_override() {  
    global $wp_rich_edit;

    if (get_user_option('rich_editing') == 'true' || !is_user_logged_in()) {
        $wp_rich_edit = true;
        return true;

    $wp_rich_edit = false;
    return false;

add_filter('user_can_richedit', 'user_can_richedit_override');  

Quickly build your own CentOS 6 & 7 AMI

Following on from my previous post Roll your own CentOS 6.5 HVM AMI in less than 15 minutes here's the snippet to for booting into an automated kickstart install for building your new AMI.

This also works for other VM providers such as Azure.

Don't forget to replace the version and appropriate snippets with your own.

version=<%= @osver %>  

# Detect primary root drive
if [ -e /dev/xvda ]; then  
elif [ -e /dev/vda ]; then  
elif [ -e /dev/sda ]; then  

yum -y install wget  
mkdir /boot/centos  
cd /boot/centos  
wget ${mirror}/${version}/os/x86_64/isolinux/vmlinuz  
wget ${mirror}/${version}/os/x86_64/isolinux/initrd.img

cat > /boot/centos/kickstart.ks << EOL  
<%= snippet 'centos_kickstart' %>

<%= snippet 'centos_post' %>  
<%= snippet 'centos_post_finish' %>  

if [ ${version} == 6 ]; then  
  echo "
  default         0
  timeout         0

  title CentOS 6 Installation
          root (hd0,0)
          kernel /boot/centos/vmlinuz ip=dhcp ksdevice=eth0 ks=hd:${drive}1:/boot/centos/kickstart.ks method=${mirror}/${version}/os/x86_64/ lang=en_US keymap=us
  initrd /boot/centos/initrd.img " > /boot/grub/grub.conf
  echo "menuentry 'centosinstall' {
          set root='hd0,msdos1'
      linux /boot/centos/vmlinuz ip=dhcp ksdevice=eth0 ks=hd:${drive}1:/boot/centos/kickstart.ks method=${mirror}/${version}/os/x86_64/ lang=en_US keymap=us
          initrd /boot/centos/initrd.img
  }" >> /etc/grub.d/40_custom

  echo 'GRUB_DEFAULT=saved
  GRUB_CMDLINE_LINUX_DEFAULT="quiet nosplash vga=771 nomodeset"
  GRUB_DISABLE_LINUX_UUID=true' > /etc/default/grub

  grub2-set-default 'centosinstall'
  grub2-mkconfig -o /boot/grub2/grub.cfg

Cleaning Up Docker Host

Sometimes testing docker images consumes a lot of diskspace depending on what you're using, if you're like me and don't have a brand new 1TB SSD then we can't afford to have diskspace wasted.

Here's a quick 3 line command to:
1. Stop all docker contaienrs
2. Remove all docker containers
3. Remove all docker images

docker stop $(docker ps -a -q)  
docker rm $(docker ps -a -q)  
docker rmi $(docker images -q)  

Now we can start fresh and try or build new docker containers. Also note, if you created external volume mount folders these commands won't remove them.

Error response from daemon: Cannot start container (....) (exit status 1)

This is a fairly generic error message, but it may help some that their iptable rules may be conflicting.

Stop using lokkit!

If you use lokkit for your iptable rules, you'll overwrite the docker rules so you'll have to service docker restart and try again.

Now the docker firewall rules should be loaded and you can start your docker container!

FATA[0000] Error response from daemon: Cannot start container a788e23879a4257918008b62bd6bfdaceb69cb6364180d1259c1348df0a4bd91: failed to find the cgroup root

Today after a reboot on a fresh CentOS 6.6 docker host, the containers were failing to startup with the error message:

FATA[0000] Error response from daemon: Cannot start container xxxxxxx: failed to find the cgroup root

Fix seems simple enough, the cgroup services aren't running:

[[email protected] ~]# /etc/init.d/cgred status
cgred is stopped  
[[email protected] ~]# /etc/init.d/cgred start
Starting CGroup Rules Engine Daemon:                       [  OK  ]  
[[email protected] ~]# /etc/init.d/cgconfig status
[[email protected] ~]# /etc/init.d/cgconfig start
Starting cgconfig service:                                 [  OK  ]

[[email protected] ~]# /etc/init.d/docker restart
Stopping docker:                                           [  OK  ]  
Starting docker:                                       [  OK  ]

[[email protected] ~]# docker run ....

Now run your containers and you should be all good to go :)

Hope this may help someone who stumbles across this. Remember to enable the services so it doesn't happen on next reboot!

chkconfig cgconfig on  
chkconfig cgred on  

Docker is fun :)