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.
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
- 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.
- 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
- How to access host's localhost from inside kubernetes cluster
- How to access key in a map returned by kubectl
- How to access Kubernetes container environment variables from React.js application?
- How to access local Kubernetes minikube dashboard remotely?
- How to access private Docker Hub repository from Kubernetes on Vagrant
- How to access remote server with local phpMyAdmin client?
- How to access HTTP headers for request to AWS API Gateway using Lambda?
- How to access mysql outside my kubernetes cluster?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.