Run Weave Net with Kubernetes in Just One Line

By Bryan Boreham
September 27, 2016

Kubernetes, the Open Source container orchestration system from Google, has very specific network requirements.  Historically people have used complex Salt and Bash scripts to configure networks to meet the requirements, but...

Related posts

Empowering Platform & Application Teams: A Closer Look at Weave GitOps Enterprise Features

Kubernetes Security - A Complete Guide to Securing Your Containers

Multi-cluster Application Deployment Made Easy with GitOpsSets

Kubernetes, the Open Source container orchestration system from Google, has very specific network requirements.  Historically people have used complex Salt and Bash scripts to configure networks to meet the requirements, but now there is a much simpler way to install Weave Net:

Kubernetes versions 1.6 and above:

    $ kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

Kubernetes versions up to 1.5:

    $ kubectl apply -f https://git.io/weave-kube

This one-liner will create a DaemonSet, a Kubernetes feature that runs one instance on each node.  Kubernetes will take care of downloading the Weave Net software from Docker Hub and starting it as configured by that weave-kube URL.  As usual with Weave Net, the nodes automatically form a mesh and are self-configuring, so you can add more nodes without changing any configuration.

To check for yourself that Weave Net is running:

    $ kubectl get pods --all-namespaces
    NAMESPACE     NAME              READY     STATUS    RESTARTS   AGE
    [...]
    kube-system   weave-net-4mylt   2/2       Running   0          18m
    kube-system   weave-net-dwueb   2/2       Running   0          18m
    kube-system   weave-net-tj1xv   2/2       Running   0          18m

There are two containers running in each pod: one handles network topology and address allocation, and the other one implements network policy enforcement.

After you’ve installed Weave Net, all pods that Kubernetes starts will be attached to the Weave network.  For example:

    $ kubectl run --image=weaveworks/hello-world hello
    $ kubectl get pods -o wide
    NAME                     READY STATUS   RESTARTS  AGE  IP
    hello-2533203682-5opib   1/1   Running  0         9s   10.32.0.2

We can see that the IP address of this pod is within Weave’s default range.

The key to Kubernetes integration with Weave Net is CNI, the Container Network Interface standard from the Cloud Native Computing Foundation.

In order for this to work, Kubernetes must be configured to use CNI.  If you use the new kubeadm command this happens by default; if instead you are using the cluster set-up scripts that come with Kubernetes it looks like:

    $ NETWORK_PROVIDER=cni cluster/kube-up.sh

If you install Kubernetes some other way, the key thing is to give the --network-plugin=cni argument to the kubelet component.

For complete and up to date information, please see "Integrating Kubernetes via the Addon"  in the Weave Net docs. 


Related posts

Empowering Platform & Application Teams: A Closer Look at Weave GitOps Enterprise Features

Kubernetes Security - A Complete Guide to Securing Your Containers

Multi-cluster Application Deployment Made Easy with GitOpsSets