microk8s
networking
kubernetes
pods
deployment

How to access hosts in my network from microk8s deployment pods

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

MicroK8s is a lightweight Kubernetes distribution ideal for local development or edge deployments. However, when running workloads in MicroK8s, you might often need your Kubernetes pods to communicate with services running on the physical host network. This article will guide you through accessing hosts in your network from MicroK8s deployment pods, including technical explanations, examples, and advanced configurations.

Understanding the Network Layer in MicroK8s

MicroK8s provides a streamlined Kubernetes experience by handling most network configurations internally. By default, Calico or Flannel is used as the CNI (Container Network Interface) to manage network resources. One key requirement is enabling intercommunication between the internal Kubernetes network and external hosts.

Networking Basics: Types and Configurations

  1. Container Networking:
    • Each pod in Kubernetes has its own internal IP address. Kubernetes manages this with sophisticated IP address management policies through its CNI.
    • These internal POD IPs are not accessible outside the cluster without network configuration.
  2. CNI Plugins:
    • Calico and Flannel are default CNIs that dictate how networks are managed within the Kubernetes cluster.
    • Different plugins might offer varying capabilities for routing and policy enforcement.

Accessing Host Network from MicroK8s Deployment Pods

To allow pods in MicroK8s to interact with hosts on the same network, consider the following methods:

1. Host Network Mode

A straightforward approach to accessing the host network is leveraging Kubernetes' host network mode. This mode lets your deployment utilize the node's network namespace directly, bypassing the internal POD network.

  • name: main-container
  • Security: Host networking is inherently less secure. Pods have full access to the host's network interface.
  • Port Conflicts: Be cautious of port conflicts between the host's services and your containerized applications.
    • protocol: TCP
  • Flexibility and isolation from the host's direct network traffic.
  • Limited number of available ports for exposing services through NodePort.
    • ip: "192.168.1.100"
      • "custom.internal"
    • name: main-container
  • This method is ideal for referencing services hosted on specific hosts not handled by common Kubernetes DNS.
  • Pod-DNS Config:
  • Besides using the default `ClusterFirst` policy, you might configure pod DNS policies as `Default` or `None` based on requirements, enabling various levels of DNS resolution.
  • Network Policies: Use Kubernetes network policies judiciously to control traffic flow to/from specific host networks, aiding in security hardening.
  • Ingress Controllers: Setup ingress to route external traffic properly while ensure efficient and secure exposures of services.
  • Virtual IPs & Load Balancers: Ensure high availability and scalability of services using external load balancers configured to route traffic from network hosts.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.