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

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

What is cloud migration? Benefits, strategy, and best practices

Cloud migration is the process of transferring digital assets, such as data, applications, and IT resources, from on-premises data centers to cloud platforms, including public, private, hybrid, or multi-cloud environments. Organizations can

What is a private cloud? Benefits, use cases, and implementation

A private cloud is a cloud computing environment dedicated exclusively to a single organization, providing a single-tenant infrastructure that improves security, control, and customization compared to public clouds.Private cloud environment

What is a cloud GPU? Definition, types, and benefits

A cloud GPU is a remotely rented graphics processing unit hosted in a cloud provider's data center, accessible over the internet via APIs or virtual machines. These virtualized resources allow users to access powerful computing capabilities

What is cloud networking: benefits, components, and implementation strategies

Cloud networking is the use and management of network resources, including hardware and software, hosted on public or private cloud infrastructures rather than on-premises equipment. Over 90% of enterprises are expected to adopt cloud netwo

Subscribe to our newsletter

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