Access Kubernetes applications via localhost from the host system - kubernetes

Is there any other way except port-forwarding, I can access the apps running inside my K8s cluster via http://localhost:port from my host operating system.
For example
I am running minikube setup to practise the K8s and I deployed three pods along with their services, I choose three different service type, Cluster IP, nodePort and LoadBalancer.
For Cluster IP, I can use port-forward option to access my app via localhost:port, but the problem is, I have to leave that command running and if for some reason, it is distributed, connection will be dropped, so is there any alternate solution here ?
For nodePort, I can only access this via minikube node IP not with the localhost, therefore, if I have to access this remotely, I wont have a route to this node IP address
For LoadBalancer, not a valid option as I am running minikube in my local system not in cloud.
Please let me know if there is any other solution to this problem, the reason why I am asking this when I deploy same application via docker compose, I can access all these services via localhost:port and I can even call them via VM_IP:port from other systems.
Thanks,
-Rafi

Related

Kubernetes service IP confusion

I'm aware that what I'm about to ask is probably an extremely basic networking question, but I'm not even sure the best way to word this to do a Google search that returns anything useful.
I'm working through a Kubernetes tutorial which suggests to get the IP address of one of my services with this command:
minikube service web --url
This returns to me http://192.168.64.2:30169. The part that confuses me is that my computer's IP address is 192.168.64.1. It seems like there are actually two IP addresses on my local network that "live" on my laptop, but when I try to access the service address from another machine on my home network the service does not load.
Question
What is really going on when each service is assigned a different IP address? What network is that on and why can I only access those services from my laptop?
I think "http://192.168.64.2" could be the IP address of the VM that minikube is running. You can check it using minikube ip. 30169 could refer to the port where the service is accessible if the service is of NodePort type. Also, these IPs are locally exposed on your computer so they may not be accessible from another computer.
Each service is assigned a virtual IP address inside the kubernetes cluster. They can be accessed from outside the cluster if they are of NodePort type. You can access them on any node of the cluster (hence multiple different IP addresses) or you could loadbalance across those node by adding a Loadbalancer or Ingress.

How to access minikube machine from outside?

I have a server running on ubuntu where I need to expose my app using kubernetes tools. I created a cluster using minikube with virtualbox machine and with the command kubectl expose deployment I was able tu expose my app... but only in my local network. It's mean that when I run minikube ip I receive a local ip. My question is how can I access my minikube machine from outside ?
I think the answer will be "port-forwarding".But how can I do that ?
You can use SSH port forwarding to access your services from host machine in the following way:
ssh -R 30000:127.0.0.1:8001 $USER#192.168.0.20
In which 8001 is port on which your service is exposed, 192.168.0.20 is minikube IP.
Now you'll be able to access your application from your laptop pointing the browser to http://192.168.0.20:30000
If you mean to access your machine from the internet, then the answer is yes "port-forwarding" and use the external ip address [https://www.whatismyip.com/]. The configurations go into your router settings. Check your router manual.

Kubernetes cannot access app via POD IP

I set up a cluster with 2 machines, which are not in the same local subnet but they can connect each other, machine A is Master + Node and machine B is Node. Then I use flannel (subnet 172.16.0.0/16) as the network plugin. After deployed apps, I encountered a problem that I can access the app via POD IP on machine A, but I cannot access the same app on machine B via POD IP, and curl command would say No route to the host172.16.0.x`.
I think there is no route rules to other machine, but I don't know how to configure the network. Could anyone help to explain if I miss something important? Thank you very much.
I use this kubernetes/contrib ansible script to deploy cluster, and did not change any configuration about flannel.
You can use the type:NodePort to access the pod over all of the node's IPs

browse kubernetes network form outside

I'm running a kubernetes cluster on AWS using Weave with a private topology. I have some multi-node applications (like Spark) that have a UI web page. I can expose that via a load balancer, but all the links to the workers, etc. use the k8s local ip addresses. Is it possible (via kubectl proxy or otherwise) to temporarily "go inside" the k8s network from a browser on my laptop, so that all the k8s internal ips work as expected? I'm not looking to expose everything to the outside, but to be able to temporarily browse for things from my laptop.
You can use weave expose to expose weave Subnet.
You should be able to use kubectl port-forward my-container-name localport:serviceport on your laptop (where service port is the port exposed by your WebUI service). Then you should be able to browse to localhost:localport and everything should work as expected.
Alternatively you may need to SSH into one of the private nodes via a bastion host.

How can I expose kubernetes services from within a local VM?

I'm running kubernetes locally in a guest VM. How can I expose services to the host?
On GKE, for example, exposing a service requisitions an IP from Google and wires it up, so that requests to that IP end up at the right service. How can I do that for my VM?
Not the wanted answer but you have to do it manually for now. I usually start a nginx container with --net=host to proxy from kubernetes network to VM network.
I hope to be wrong but it was true some month ago.