This is a very annoying task.
With nothing special on hands, you need to redirect a port from your modem to your machine.
Most of people have non-fixed public ips, so you need to find your public ip address (you cant search for "what is my ip") and hope that it don't change between your tests.
With your public ip address you can try to access directly from pod, ex:
kubectl exec -ti alpine-pod -- curl 150.136.143.228:8080
Some clusters don't let the pod go outside from their own, so, better create an service without selectors and then add the an endpoint pointing to your ip:
apiVersion: v1
kind: Service
metadata:
name: to-my-home
spec:
ports:
- protocol: TCP
port: 80
targetPort: 8080
Then, add the endpoint:
apiVersion: v1
kind: Endpoints
metadata:
name: to-my-home
subsets:
- addresses:
- ip: 150.136.143.228
ports:
- port: 8080
Now, if you're inside in the same namespace that service, you cand do this:
kubectl exec -ti alpine-pod -- curl to-my-home
An better, and easy, solution is to use vagrant share, https://www.vagrantup.com/docs/share, but you need some steps:
- Install an hypervisor (VirtualBox, Libvirt, HyperV, VMWare)
- Install Vagrant
- Create and account on https://app.vagrantup.com
- Start a machine and use vagrant share
- Grab the URL showed on command return and use on pod/service, the port is always 80
Example:
vagrant init debian/buster64
vagrant login
vagrant up
vagrant share