Wednesday, July 21, 2021

Access a service with port forward

 Let's see the list of services available.

osboxes@osboxes:~/Desktop/learn-consul-kubernetes0/service-mesh/deploy$ kubectl get svc -n consul-testing
NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
frontend      ClusterIP   10.96.212.218   <none>        80/TCP     3m18s
postgres      ClusterIP   10.96.95.55     <none>        5432/TCP   3m18s
product-api   ClusterIP   10.96.27.19     <none>        9090/TCP   3m17s
public-api    ClusterIP   10.96.233.41    <none>        8080/TCP   3m17s

We can see the service frontend is of type ClusterIP, to access it we need to change the type to LoadBalancer. You can do that using this command and can access with the External IP generated and the redirection port(default 80).

Sample output:

consul-ui                     LoadBalancer   10.96.54.55     172.19.150.200   80:32327/TCP   

Or, you can access it temporarily using port-forward.

kubectl port-forward service/frontend 18080:80 --address 0.0.0.0

This will make it available temporarily as long the console is running and you can stop it with ctrl+c.

You can access it with localhost:18080 and the same traffic will be routed to container port 80.

available at http://localhost:18080 in your browser


No comments:

Post a Comment