Switches: operate at data link layer (layer 2)
ip link
ip addr
Routers: operate at layer 3
ip route
ip route add <target-subnet-cidr> via <ip-addr>
Create and list network namespaces with ip netns
.
Linux Bridge lets you connect all namespaces to an interface that works like a vritual switch:
sudo ip link add my-bridge type bridge
sudo ip link set dev my-bridge up
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:
You can access a service:
printenv
)Service only reachable within cluster, default
targetPort
of pods that the service defines as targetsExample 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.
exposes service on each Node’s IP at static port, automatically creates ClusterIP
Multiple pods:
exposes service externally using external load balancer, automatically creates NodePort and ClusterIP
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:
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.
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).
Two types of CNI plugins: