I have a pod and service running but no deployment exist. If i want to expose th . . .

Muhamed Hussain:
I have a pod and service running but no deployment exist. If i want to expose the service out to my local desktop from the minikube instance ? Is there any way.

Was trying to assign external ip or expose operation but all needs a deployemnt.

Manu Mittal:
is your service running on nodeport

Manu Mittal:
change the type of the service to load balancer and you will get the random node port to expose the service outside

Aneek Bera:
use loadbalancer to get external IP

Aneek Bera:
or expose the service as --type=NodePort

Mouhamadou Moustapha Camara:
HI @Muhamed Hussain,
Use this document to see how to get service link using minikube. https://minikube.sigs.k8s.io/docs/handbook/accessing/

As you have a pod, not deployment you just need to adapt the expose command :

kubectl expose pod <your_pod_name> --type=NodePort --port=<pod_port>

If you’re on MacOS you need to do some extra work to have the link, read the section service tunnel

Thank

Trung Tran:
From a local cluster, a simple way to access the pod/service is using port-forwarding
Service:
kubectl port-forward service/myservice 5000 6000
Pod:
kubectl port-forward pod/mypod 8888:5000

After forward, you can access pod/service using host network like http://localhost:8888

Trung Tran:
For an example, I have a nginx pod running on my minikube cluster
kubectl run nginx --image=nginx:alpine
nginx 1/1 Running
I can use this command to forward host port to the default port of nginx container inside pod (80)
kubectl port-forward pod/nginx 8888:80

Then I can open my browser and access the nginx container via http://localhost:8888, it will return the default welcome page of NGINX.
Similar to the service, it not how we expose app on production but for a quick check on local, it should be fine.

Muhamed Hussain:
Thank you all for the response. Both port forwarding and tunneling needs my terminal session open. But to expose with external IP i have to change my pod type from NodePort to LoadBalancer.

Trung Tran:
Yeah, I thought you need expose it for a short term to check or debug something, if you need it run like a host, loadbalancer or nodeport will be required for sure.

Muhamed Hussain:
Its already NodePort type. How can we expose this for long ?

Trung Tran:
I don’t think we can do that with local PC if you don’t want to keep the terminal running.

Muhamed Hussain:
Can we use an nginx ingress controller and achieve this ?

unnivkn:
Hi @Muhamed Hussain if your k8s cluster is configured on Local VM’s then you can expose your app using nodePort svc.
In order to work Loadbalancer you need to deploy your app & svc in a managed k8s like eks or aks.