Instructions for setting up a Kubernetes cluster.

Documentation for Kubernetes v1.8 is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date documentation, see the latest version.

Edit This Page

CoreOS on libvirt


Warnings about libvirt-coreos use case

The primary goal of the libvirt-coreos cluster provider is to deploy a multi-node Kubernetes cluster on local VMs as fast as possible and to be as light as possible in term of resources used.

In order to achieve that goal, its deployment is very different from the “standard production deployment” method used on other providers. This was done on purpose in order to implement some optimizations made possible by the fact that we know that all VMs will be running on the same physical machine.

The libvirt-coreos cluster provider doesn’t aim at being production look-alike.

Another difference is that no security is enforced on libvirt-coreos at all. For example,

So, a k8s application developer should not validate its interaction with Kubernetes on libvirt-coreos because he might technically succeed in doing things that are prohibited on a production environment like:

On the other hand, libvirt-coreos might be useful for people investigating low level implementation of Kubernetes because debugging techniques like sniffing the network traffic or introspecting the etcd content are easier on libvirt-coreos than on a production deployment.


  1. Install dnsmasq
  2. Install ebtables
  3. Install qemu
  4. Install libvirt
  5. Install openssl
  6. Enable and start the libvirt daemon, e.g.:

    • systemctl enable libvirtd && systemctl start libvirtd for systemd-based systems
    • /etc/init.d/libvirt-bin start for init.d-based systems
  7. Grant libvirt access to your user¹
  8. Check that your $HOME is accessible to the qemu user²

¹ Depending on your distribution, libvirt access may be denied by default or may require a password at each access.

You can test it with the following command:

virsh -c qemu:///system pool-list

If you have access error messages, please read and

In short, if your libvirt has been compiled with Polkit support (ex: Arch, Fedora 21), you can create /etc/polkit-1/rules.d/50-org.libvirt.unix.manage.rules as follows to grant full access to libvirt to $USER

sudo /bin/sh -c "cat - > /etc/polkit-1/rules.d/50-org.libvirt.unix.manage.rules" << EOF
polkit.addRule(function(action, subject) {
        if ( == "org.libvirt.unix.manage" &&
            subject.user == "$USER") {
                return polkit.Result.YES;
                polkit.log("action=" + action);
                polkit.log("subject=" + subject);

If your libvirt has not been compiled with Polkit (ex: Ubuntu 14.04.1 LTS), check the permissions on the libvirt unix socket:

$ ls -l /var/run/libvirt/libvirt-sock
srwxrwx--- 1 root libvirtd 0 févr. 12 16:03 /var/run/libvirt/libvirt-sock

$ usermod -a -G libvirtd $USER
# $USER needs to logout/login to have the new group be taken into account

(Replace $USER with your login name)

² Qemu will run with a specific user. It must have access to the VMs drives

All the disk drive resources needed by the VM (CoreOS disk image, Kubernetes binaries, cloud-init files, etc.) are put inside ./cluster/libvirt-coreos/libvirt_storage_pool.

As we’re using the qemu:///system instance of libvirt, qemu will run with a specific user:group distinct from your user. It is configured in /etc/libvirt/qemu.conf. That qemu user must have access to that libvirt storage pool.

If your $HOME is world readable, everything is fine. If your $HOME is private, cluster/ will fail with an error message like:

error: Cannot access storage file '$HOME/.../kubernetes/cluster/libvirt-coreos/libvirt_storage_pool/kubernetes_master.img' (as uid:99, gid:78): Permission denied

In order to fix that issue, you have several possibilities:

On Arch:

setfacl -m g:kvm:--x ~


By default, the libvirt-coreos setup will create a single Kubernetes master and 3 Kubernetes nodes. Because the VM drives use Copy-on-Write and because of memory ballooning and KSM, there is a lot of resource over-allocation.

There is both an automated way and a manual, customizable way of setting up libvirt Kubernetes clusters on CoreOS.

Automated setup

There is an automated setup script on that will download the tarball for Kubernetes and spawn a Kubernetes cluster on a local CoreOS instances that the script creates. To run this script, use wget or curl with the KUBERNETES_PROVIDER environment variable set to libvirt-coreos:

export KUBERNETES_PROVIDER=libvirt-coreos; wget -q -O - | bash

Here is the curl version of this command:

export KUBERNETES_PROVIDER=libvirt-coreos; curl -sS | bash

This script downloads and unpacks the tarball, then spawns a Kubernetes cluster on CoreOS instances with the following characteristics:

If you’d like to run this cluster with customized settings, follow the manual setup instructions.

Manual setup

To start your local cluster, open a shell and run:

cd kubernetes

export KUBERNETES_PROVIDER=libvirt-coreos

The KUBERNETES_PROVIDER environment variable tells all of the various cluster management scripts which variant to use. If you forget to set this, the assumption is you are running on Google Compute Engine.

The NUM_NODES environment variable may be set to specify the number of nodes to start. If it is not set, the number of nodes defaults to 3.

The KUBE_PUSH environment variable may be set to specify which Kubernetes binaries must be deployed on the cluster. Its possible values are:


You can check that your machines are there and running with:

$ virsh -c qemu:///system list
 Id    Name                           State
 15    kubernetes_master              running
 16    kubernetes_node-01             running
 17    kubernetes_node-02             running
 18    kubernetes_node-03             running

You can check that the Kubernetes cluster is working with:

$ kubectl get nodes
NAME                STATUS     AGE     VERSION        Ready      4h      v1.6.0+fff5156        Ready      4h      v1.6.0+fff5156        Ready      4h      v1.6.0+fff5156

The VMs are running CoreOS. Your ssh keys have already been pushed to the VM. (It looks for ~/.ssh/id_*.pub) The user to use to connect to the VM is core. The IP to connect to the master is The IPs to connect to the nodes are and onwards.

Connect to kubernetes_master:

ssh core@

Connect to kubernetes_node-01:

ssh core@

Interacting with your Kubernetes cluster with the kube-* scripts.

All of the following commands assume you have set KUBERNETES_PROVIDER appropriately:

export KUBERNETES_PROVIDER=libvirt-coreos

Bring up a libvirt-CoreOS cluster of 5 nodes

NUM_NODES=5 cluster/

Destroy the libvirt-CoreOS cluster


Update the libvirt-CoreOS cluster with a new Kubernetes release produced by make release or make release-skip-tests:


Update the libvirt-CoreOS cluster with the locally built Kubernetes binaries produced by make:

KUBE_PUSH=local cluster/

Interact with the cluster

kubectl ...


!!! Cannot find kubernetes-server-linux-amd64.tar.gz

Build the release tarballs:

make release

Can’t find virsh in PATH, please fix and retry.

Install libvirt

On Arch:

pacman -S qemu libvirt

On Ubuntu 14.04:

aptitude install qemu-system-x86 libvirt-bin

On Fedora 21:

yum install qemu libvirt

error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock’: No such file or directory

Start the libvirt daemon

On Arch:

systemctl start libvirtd virtlogd.socket

The virtlogd.socket is not started with the libvirtd daemon. If you enable the libvirtd.service it is linked and started automatically on the next boot.

On Ubuntu 14.04:

service libvirt-bin start

error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock’: Permission denied

Fix libvirt access permission (Remember to adapt $USER)

On Arch and Fedora 21:

cat > /etc/polkit-1/rules.d/50-org.libvirt.unix.manage.rules <<EOF
polkit.addRule(function(action, subject) {
        if ( == "org.libvirt.unix.manage" &&
            subject.user == "$USER") {
                return polkit.Result.YES;
                polkit.log("action=" + action);
                polkit.log("subject=" + subject);

On Ubuntu:

usermod -a -G libvirtd $USER

error: Out of memory initializing network (virsh net-create…)

Ensure libvirtd has been restarted since ebtables was installed.

Support Level

IaaS Provider Config. Mgmt OS Networking Docs Conforms Support Level
libvirt/KVM CoreOS CoreOS libvirt/KVM docs   Community (@lhuard1A)

For support level information on all solutions, see the Table of solutions chart.


Create an Issue Edit this Page