Software Containerisation

Table of Contents

Networking

Switches: operate at data link layer (layer 2)

Routers: operate at layer 3

Create and list network namespaces with ip netns.

Linux Bridge lets you connect all namespaces to an interface that works like a vritual switch:

Kubernetes network model

Constraints:

You may impose restrictions on the model using Kubernetes Network Policies.

Container Network Interface (CNI): formalises responsibilities of Container Runtime (creating network namespace and running plugins)

Pods can be:

Kubernetes Services

You can access a service:

ClusterIP

Service only reachable within cluster, default

Example definition using selector:

apiVersion: v1
kind: Service

metadata:
    name: fancy-api-service

spec:
    type: ClusterIP
    ports:
        - protocol: TCP
          port: 8081
          targetPort: 80
    selector:
        app: fancy-api

Apply with kubectly apply -f filename.yaml, then check with kubectl get svc.

Creating a service using a selector also automatically adds an Endpoint object.

You can create a service without a pod selector, e.g. if you need to target a pod in a different cluster.

NodePort

exposes service on each Node’s IP at static port, automatically creates ClusterIP

Multiple pods:

LoadBalancer

exposes service externally using external load balancer, automatically creates NodePort and ClusterIP

Ingress

Layer 7 load balancer, operates at app layer using HTTP, can route decision based on full content of message. Useful when you have multiple services you want to expose externally.

To use it:

  1. Install Ingress Controller
    • e.g. NGINX Ingress controller, Google HTTPS Load Balancer
  2. Create Ingress Resources

CoreDNS

Provides nameserver for Kubernetes. Nameserver can be referenced from Unix machine if it has an entry in /etc/resolv.conf

To resolve a hostname, use nslookup and dig.

In microk8s, run microk8s enable dns to add CoreDNS.

Stores its config in a file called Corefile; in Kubernetes, it’s a ConfigMap.

Network Policies

Implemented by Network Plugin (e.g. Calico).

By default, pods accept traffic from any source in Cluster. With Network Policies that select a Pod, the Pod is restricted by the union of the policies’ ingress and egress rules (order of application of policies doesn’t matter, it’s a union).

Calico

Two types of CNI plugins: