Setting Up Kubernetes Networking with Weave Net

1 hour
  • 2 Learning Objectives

About this Hands-on Lab

The Kubernetes networking model creates a virtual network that is accessible to all pods within the cluster. Weave Net is one of several tools that provide an implementation of the Kubernetes networking model. In this learning activity, you will learn how to configure a Kubernetes pod network using Weave Net. After completing the activity, you will have hands-on experience implementing networking within a Kubernetes cluster.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Enable IP forwarding on all worker nodes.

In order for Weave Net to work, you need to make sure IP forwarding is enabled on the worker nodes. Enable it by running the following on both workers:

sudo sysctl net.ipv4.conf.all.forwarding=1
echo "net.ipv4.conf.all.forwarding=1" | sudo tee -a /etc/sysctl.conf
Install Weave Net in the cluster.

Do the following on the controller server:

  1. Install Weave Net using a configuration from Weaveworks like this:

    kubectl apply -f "$(kubectl version | base64 | tr -d 'n')&env.IPALLOC_RANGE="
  2. Verify that everything is working:

    kubectl get pods -n kube-system

    This should return two weave-net pods and look something like this:

    NAME              READY     STATUS    RESTARTS   AGE
    weave-net-m69xq   2/2       Running   0          11s
    weave-net-vmb2n   2/2       Running   0          11s
  3. Spin up some pods to test the networking functionality:

    a. First, create an Nginx deployment with 2 replicas:

    cat << EOF | kubectl apply --kubeconfig admin.kubeconfig -f -
    apiVersion: apps/v1
    kind: Deployment
     name: nginx
         run: nginx
     replicas: 2
           run: nginx
         - name: my-nginx
           image: nginx
           - containerPort: 80

    b. Next, create a service for that deployment so that we can test connectivity to services as well:

    kubectl expose deployment/nginx

    c. Start up another pod. We will use this pod to test our networking. We will test whether we can connect to the other pods and services from this pod.

    kubectl run busybox --image=radial/busyboxplus:curl --command -- sleep 3600
    POD_NAME=$(kubectl get pods -l run=busybox -o jsonpath="{.items[0]}")

    d. Get the IP addresses of our two nginx pods:

    kubectl get ep nginx

    There should be two IP addresses listed under ENDPOINTS. For example:

    NAME      ENDPOINTS                       AGE
    nginx,   50m
  4. Make sure the busybox pod can connect to the nginx pods on both of those IP addresses.

    kubectl exec $POD_NAME -- curl <first nginx pod IP address>
    kubectl exec $POD_NAME -- curl <second nginx pod IP address>

    Both commands should return some HTML with the title "Welcome to Nginx!" This means that we can successfully connect to other pods.

  5. Now let’s verify that we can connect to services.

    kubectl get svc

    This should display the IP address for our Nginx service. For example, in this case, the IP is

    kubernetes   ClusterIP    <none>        443/TCP   1h
    nginx        ClusterIP   <none>        80/TCP    53m
  6. Check that we can access the service from the busybox pod.

    kubectl exec $POD_NAME -- curl <nginx service IP address>

    This should also return HTML with the title "Welcome to nginx!"

Getting this response means that we have successfully reached the Nginx service from inside a pod and that our networking configuration is working!

Additional Resources

Your team is configuring a new Kubernetes cluster to run your company’s new online store. The controller and worker nodes have been set up, but some of the pods in your infrastructure will need to communicate with each other. Therefore, you need to configure Kubernetes networking. In this learning activity, you will implement networking in a Kubernetes cluster using Weave Net.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?