I haven't found a way to expose the minikube instance with --driver=docker to the host network (apart from $ kubectl port-forward svc/svc-name --address=0.0.0.0 local_port:pod_port ran on the host).
It produces the same error as original poster is experiencing:
Error response from daemon: operation is not permitted on predefined host network
Acknowledging following comment:
the problem is that I want to use the ingress addon and this addon is not compatible anymore with --driver=none.
Instead of using --driver=docker which will place all of the resources in the Docker container, you can opt for a --driver=none which will provision all of your resources directly on the VM. You will be able to directly query the resources from other network devices.
For now minikube version v1.17.1 does not allow to use the ingress addon with --driver=none but I found a way it could be provisioned. I've included this example on the end of this answer. Please treat this as a workaround.
This issue (inability to use ingress addon on --driver=none) is already addressed on github:
Talking from the perspective of exposing minikube:
As it's intended for accessing from external sources, I do recommend trying out other solutions that will subjectively speaking have easier time exposing your workloads to the external sources. There are many available tools that spawn Kubernetes clusters and you can look which suits your needs the most. Some of them are:
Deploying nginx-ingress with minikube --driver=none
As stated previously, please treat it as a workaround.
A side note!
Take a look on how your NGINX Ingress controller is configured with minikube addons enable ingress as it will be pretty much mimicked in this example.
Steps:
Download the nginx-ingress YAML manifest:
- Modify the
Deployment in the manifest
- Delete the
Service from manifest
- Apply and check
Download the nginx-ingress YAML manifest
You can use following manifest:
Modify the Deployment in the manifest
As I said previously, what is happening when you run minikube addons enable ingress could prove useful. The resources deployed have some clues on how you need to modify it.
- Add the
hostPort for HTTP and HTTPS communication:
ports:
- name: http
hostPort: 80 # <-- IMPORTANT, ADD THIS
containerPort: 80
protocol: TCP
- name: https
hostPort: 443 # <-- IMPORTANT, ADD THIS
containerPort: 443
protocol: TCP
- name: webhook
containerPort: 8443
protocol: TCP
- Delete the
--publish-service=$(POD_NAMESPACE)/ingress-nginx-controller:
args:
- /nginx-ingress-controller
- --publish-service=$(POD_NAMESPACE)/ingress-nginx-controller # <-- DELETE THIS
- --election-id=ingress-controller-leader
- --ingress-class=nginx
- --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
- --validating-webhook=:8443
- --validating-webhook-certificate=/usr/local/certificates/cert
- --validating-webhook-key=/usr/local/certificates/key
Delete the Service from manifest
You will need to entirely delete the Service of type LoadBalancer named: ingress-nginx from the manifest as you will already be using hostPort.
After this steps you should be able to use Ingress resources and communicate with them on VM_IP:80/443.
Additional resources: