Gaming industry under DDoS attack. Get DDoS protection now. Start onboarding
  1. Home
  2. Developers
  3. Configure Kubernetes Network with Flannel

Configure Kubernetes Network with Flannel

  • By Gcore
  • April 4, 2023
  • 3 min read
Configure Kubernetes Network with Flannel

Introduction

Network overlays in Kubernetes clusters are used to address containers, pods, services and external client connectivity.  Overlays are software components that decouple the physical infrastructure from networking services. Overlays encapsulate a packet-within-a-packet to achieve connectivity and routing. An overlay is a virtual network serving on the underlying network or underlay. An underlay is a physical infrastructure supporting connectivity.

The Kubernetes Network Model is that every pod gets its own IP address. You do not have to create link pods manually. Container-to-host port mapping is simplified. Pods are treated like Virtual Machines for port allocation, naming, service discovery, load balancing, application configuration, and migration. Pods can communicate with all nodes without Network Address Translation. And Agents (daemons or kubelets) on a node can communicate with all pods on that node.  

Flannel

Flannel is an open-source virtual network project managed by CoreOS network designed for Kubernetes. Each host in a flannel cluster runs an agent called flanneld. It assigns each host a subnet, which acts as the IP address pool for containers running on the host. Containers can then contact other containers directly, using their IP address. Flannel supports multiple backends for encapsulating packets. The recommended choice is Virtual Extensible LAN (VXLAN), which runs a Layer 2 network on top of a Layer 3 infrastructure. Flannel also supports host-gw, which maps direct routes between hosts in a manner similar to Calico.

Setup

We will be setting up our Kubernetes cluster network using the Flannel network add-on. And although the network plug-in is not provided out of the box, it is required for your cluster to run properly. So, for the pods to communicate with each other, a pod network add-on must be installed.

Kubernetes supports several different network add-on solutions. But for the purpose of this article, we will be using flannel. Moving on to installing the flannel network add-on the first thing that we need to do is there’s a sysctl value that we need to set up on all our servers, including master node:

echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf

This will permanently set that value, which will remain set even if we restart the server.  

In order to apply that change which we just added to the sysctl.conf file, we have to run the following command:

sudo sysctl -p
-p: Load sysctl settings from the file specified or /etc/sysctl.conf if none is given

And we need to do this on all of our cluster nodes.

Moving forward,  we will install flannel using the yml template that’s provided by CoreOS and their repositories on GitHub. This template is also going to create several different objects allowing Flannel to run successfully. And we are going to be doing this on our master node which is an important step. Make sure that you don’t accidentally try to install it on one of your cluster nodes. Remember to run it just on the Kubernetes master:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
kubectl apply -f: Apply a configuration change to a resource from a file or stdin.

It is just a yml file which describes the objects required to be installed in a cluster to set up Flannel and get it working. This will also create a whole bunch of objects that are specified by that yml file. So, at this point, that’s all! Flannel is installed and everything should be up and running.

You can see from the output that there are several objects that are created here and to verify this installation please run the following:

kubectl get nodes

And we see that our master server, as well as our cluster nodes, are in the Ready state. Earlier those were not ready as networking was not installed then. This helps us validate that we have set up our cluster network correctly.

All the back end system pods run in the kube-system namespace, and that includes our Flannel pods. Another way to make sure that the actual Flannel pods are up and running at this point, we have to run the following:

kubectl get pods -n kube-system

And you will see that we have our kube-flannel-ds-* pods running. So this validates that our cluster network is configured correctly.

At this point, we have set up a working and functional Kubernetes cluster.

Conclusion

Kubernetes supports a variety of different network solutions and plugins which can implement Kubernetes networking in a variety of different environments. As we see, Flannel is a networking solution that perfectly meets the functionality of the Kubernetes networking model, and it offers a simple networking model that sets up an environment which is suitable for most users and use cases when you only need the basics.

Discover more with Gcore Managed Kubernetes

Related articles

Multi-Cloud Plan: What It Is and How It Works

Your cloud provider goes down. Applications fail. Customers can't access your services. And because you've built everything around a single vendor, there's nothing you can do but wait. For organizations locked into one cloud platform, this

Vendor Lock-In in Cloud Computing: What It Is and How to Avoid It

Imagine discovering that migrating your company's data to a new cloud provider will cost hundreds of thousands of dollars in egress fees alone, before you've even touched the re-engineering work. Or worse, picture being in Synapse Financial

What Is Sovereign Cloud and Why Does It Matter?

Picture this: a foreign government issues a legal order forcing your cloud provider to hand over sensitive patient records, classified research data, or critical national infrastructure details. You can't stop it. This isn't hypothetical. G

Types of Virtualization in Cloud Computing

Your physical servers are sitting idle at 15% to 20% CPU utilization while you're paying for 100% of the power, cooling, and hardware costs. Meanwhile, your competitors have consolidated 10 to 15 applications per server, pushing utilization

What's the difference between multi-cloud and hybrid cloud?

Multi-cloud and hybrid cloud represent two distinct approaches to distributed computing architecture that build upon the foundation of cloud computing to help organizations improve their IT infrastructure.Multi-cloud environments involve us

What is multi-cloud? Strategy, benefits, and best practices

Multi-cloud is a cloud usage model where an organization utilizes public cloud services from two or more cloud service providers, often combining public, private, and hybrid clouds, as well as different service models, such as Infrastructur

Subscribe to our newsletter

Get the latest industry trends, exclusive insights, and Gcore updates delivered straight to your inbox.