Show me the code! – By Davanum Srinivas

April 21, 2016

Quick start Kubernetes in an OpenStack Environment

Filed under: Uncategorized — Davanum Srinivas @ 8:07 am

Here’s a quick way for those who want to try Kubernetes in an existing OpenStack environment:

  • Deploy a VM using an image that has Docker built in. We pick one used by Magnum in the OpenStack CI environment
  • Use the cloud-init functionality during Nova boot process to start Kubernetes

Here’s the script we inject during Nova boot process:


# Switch off SE-Linux
setenforce 0

# Set the name server
sudo sh -c 'echo "nameserver" > /etc/resolv.conf'

# Get the latest stable version of kubernetes
export K8S_VERSION=$(curl -sS

echo "Starting docker service"
sudo systemctl enable docker.service
sudo systemctl start docker.service --ignore-dependencies
echo "Checking docker service"
sudo docker ps

# Run the docker containers for kubernetes
echo "Starting Kubernetes containers"
sudo docker run \
    --volume=/:/rootfs:ro \
    --volume=/sys:/sys:ro \
    --volume=/var/lib/docker/:/var/lib/docker:rw \
    --volume=/var/lib/kubelet/:/var/lib/kubelet:rw \
    --volume=/var/run:/var/run:rw \
    --net=host \
    --pid=host \
    --privileged=true \
    --name=kubelet \
    -d \${K8S_VERSION} \
    /hyperkube kubelet \
        --containerized \
        --hostname-override="" \
        --address="" \
        --api-servers=http://localhost:8080 \
        --config=/etc/kubernetes/manifests \
        --allow-privileged=true --v=2

And here’s how you upload the image from Magnum into glance and then use nova boot to start it up (using the nova and glance python clients).


export OS_REGION_NAME=RegionOne
export OS_PASSWORD=xyz123
export OS_AUTH_URL=
export OS_USERNAME=dsrinivas
export OS_TENANT_NAME=Commons

curl -o fedora-atomic-latest.qcow2 \

glance image-create --name "fedora-23-atomic" \
    --disk-format "qcow2" \
    --container-format=bare \
    --file fedora-atomic-latest.qcow2

nova boot \
    --key-name "k8s-keypair" \
    --flavor "m1.medium" \
    --image "fedora-23-atomic" \
    --user-data \
    --config-drive true \


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: