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:

#!/bin/sh

# Switch off SE-Linux
setenforce 0

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

# Get the latest stable version of kubernetes
export K8S_VERSION=$(curl -sS https://storage.googleapis.com/kubernetes-release/release/stable.txt)
echo "K8S_VERSION : ${K8S_VERSION}"

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 \
    gcr.io/google_containers/hyperkube-amd64:${K8S_VERSION} \
    /hyperkube kubelet \
        --containerized \
        --hostname-override="127.0.0.1" \
        --address="0.0.0.0" \
        --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).

#!/bin/sh

export OS_REGION_NAME=RegionOne
export OS_PASSWORD=xyz123
export OS_AUTH_URL=http://172.18.184.20:5000/v2.0
export OS_USERNAME=dsrinivas
export OS_TENANT_NAME=Commons

curl -o fedora-atomic-latest.qcow2 \
    https://fedorapeople.org/groups/magnum/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 kube-init.sh \
    --config-drive true \
    "my-k8s"

Resources:

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.