Access service on host from pod on minikube

I’m trying to follow this guide: https://minikube.sigs.k8s.io/docs/handbook/host-access/

But host.minikube.internal from my pod solve to 127.0.0.1 that is obviously not the ip that I need to reach a service hosted on host. My minikube version is 1.32.0
I need this for development only. I’m also using Tilt.

You are right, in minikube versions above 1.10, host.minikube.internal within a pod resolves to 127.0.0.1 (local host) and won’t reach your host machine. Here are alternative approaches for development purposes:

Nodeport Service is simple but Might require Firewall Rules:

  • Use kubectl expose deploy < your -deployment-name> - - -type=Nodeport- - -port=3333- - - targetport=80 (replace with your ports)
  • Use kubectl get svc to find the allocated Node port
  • Access the service from your pod using the minikube VMs IP address and the Nodeport.<VM_IP> : 3000 (replace with the actual VM Ip address)

NOTE:

you might need to adjust firewall rules on the Minikube VM to allow traffic on the Nodeport.

Service Account with Host Network Access more secure but require pod spec modification:

  • Create a Service Account with host network access:
  • Kubectl creates a service account host-access
  • Kubectl create cluster role binding host-access-binding–cluster role system:host—service account=default:host -access

Modify your pod spec to use the service Account:

   YAML:
    
    Apiversion:v1 
    Kind:pod 
    metadata:
      name:  my-pod
    Spec: 
     Service AccountName:
    host-access
  • Deploy the pod with the modified spec.

NOTE:

This approach avoids exposing ports to the wider network like with Nodeport and is considered more secure for development environments.

Minikube tunnel simplest but limited scope:

Run minikube tunnel This creates a tunnel between your local machine and the Minikube VM,allowing you to access services running on the VM using localhost:

NOTE:

This approach only works on your local development machine and won’t be accessible from other machines on your network.

Choose the approach that best suits your needs based on simplicity, security, and accessibility requirements

Consider using Tilt’s environment variables feature to inject the VM IP address into your pods if using the Nodeport service.

Refer to the Minikube documentation for more details on service types and host network access

By following these approaches, you should access your host machine’s service from your pod in Minikube for development purposes.


EDIT-1

Why host.minikube.internal points to local host

The document for Minikube versions above 1.10 states that host.minikube internally should resolve to the minikube VM’s IP address within a pod, allowing you to reach services running on the host machine.

However, in your case version 1.32.0, it’s resolving to 127.0.0.1 local host within the pod, which won’t work for accessing the host.There might be a bug or configuration issue specific to Minikube version 1.32.0

Alternative solutions:

Minikube dns –proxy flag : (Recommended )

Starting Minikube with the – – – dns -proxy flag can potentially fix the issue with host.minikube.internal in your version

Run minikube start- -dns-proxy or add this flag to your existing minikube configuration

If successful, host.minikube.internal should resolve to the Minikube VM’s IP address within your pod, allowing you to access services running on the host machine.

Minikube VM IP Address:

If the – – – dns -proxy flag doesn’t work you can directly use the Minikube VM’s IP address to access services on the host machine from the pod

Use a Minikube VM’s IP address to access services on the host machine from your pod

To find VM IP Address run Minikube ip to get the IP Address of the Minikube VM.
Access the service using the Ip address and port <VM_IP>:<service port> (replace with actual values)

In case you are using Tilt, there is a possibility of injecting an environment variable such as Minikube VM IP address into pods via Tilt’s environment variables feature. This makes it easy for users since no amendment on pod specs is necessary if they want to reach their local services.

Through either –dns-proxy flag, or directly applying IP address of the Kubernetes node, accessing all these resources is allowed.

10

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật