Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Setting Up Kubernetes Networking with Weave Net

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.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 0m
Published
Clock icon Sep 28, 2018

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    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
    
  2. Challenge

    Install Weave Net in the Cluster

    Do the following on the controller server:

    Log in to the controller server in a new terminal window, and then do the following:

    1. Get the configuration from Weaveworks like this:

      wget https://github.com/weaveworks/weave/releases/download/v2.6.0/weave-daemonset-k8s-1.11.yaml
      
    2. Edit the configuration file with vim.

      vim weave-daemonset-k8s-1.11.yaml
      
    3. Add the following lines (press Escape and then enter i for insert mode):

      - name: IPALLOC_RANGE
        value: 10.200.0.0/16
      
    4. The edited code snippet should then look like this:

          spec:
            containers:
              - name: weave
                command:
                  - /home/weave/launch.sh
                env:
                  - name: IPALLOC_RANGE
                    value: 10.200.0.0/16
                  - name: HOSTNAME
      
      
    5. Save the file by pressing Escape and then entering :wq! .

    6. Apply the configuration with:

      kubectl apply -f ./weave-daemonset-k8s-1.11.yaml
      
    7. 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
    
    1. Spin up some Pods to test the networking functionality by first creating an Nginx deployment with two replicas:
    cat << EOF | kubectl apply --kubeconfig admin.kubeconfig -f -
       apiVersion: apps/v1
       kind: Deployment
       metadata:
         name: nginx
       spec:
         selector:
           matchLabels:
             run: nginx
         replicas: 2
         template:
           metadata:
             labels:
               run: nginx
           spec:
             containers:
             - name: my-nginx
               image: nginx
               ports:
               - containerPort: 80
    EOF
    
    1. Next, create a service for that deployment so that we can test connectivity to services as well:
    kubectl expose deployment/nginx
    
    1. 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].metadata.name}")
    
    1. 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     10.200.0.2:80,10.200.128.1:80   50m
    
    1. 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.

    1. 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 10.32.0.54:

    NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
    kubernetes   ClusterIP   10.32.0.1    <none>        443/TCP   1h
    nginx        ClusterIP   10.32.0.54   <none>        80/TCP    53m
    
    1. 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!

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans