<p>Is it somehow possible to expose a kubernetes service to the outside world?
I am currently developping an application which need to communicate with a service, and to do so I need to know the pod ip and port address, which I withing the kubernetes cluster can get with the kubernetes services linked to it, but outside the cluster I seem to be unable to find it, or expose it?</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: kafka-broker
spec:
  ports:
  - name: broker
    port: 9092
    protocol: TCP
    targetPort: kafka
  selector:
    app: kafka
  sessionAffinity: None
  type: ClusterIP
</code></pre>

<p>I could containerize the application, put it in a pod, and run it within kubernetes, but for fast development it seems tedious to have to go through this, for testing such a small things such as connectivity? </p>

<p>Someway i can expose  the service, and thereby reach the application in its selector?</p>

some
<p>In order to expose your Kubernetes service to the internet you must change the <code>ServiceType</code>.</p>

<p>Your service is using the default which is <code>ClusterIP</code>, it exposes the Service on a cluster-internal IP, making it <strong>only reachable within the cluster</strong>.</p>

<p><strong>1 - If you use cloud provider like AWS or GCP The best option for you is to use the <code>LoadBalancer</code> Service Type:</strong> which automatically exposes to the internet using the provider Load Balancer.</p>

<p>Run:
 <code>kubectl expose deployment deployment-name --type=LoadBalancer --name=service-name</code></p>

<p><em>Where <code>deployment-name</code> must be replaced by your actual deploy name. and the same goes for the desired <code>service-name</code></em></p>

<p>wait a few minutes and the <code>kubectl get svc</code> command will give you the external IP and PORT:</p>

<pre><code>owilliam@minikube:~$ kubectl get svc
NAME               TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)      AGE
kubernetes         ClusterIP      10.96.0.1       &lt;none&gt;        443/TCP      4d21h
nginx-service-lb   LoadBalancer   10.96.125.208   0.0.0.0     80:30081/TCP   36m
</code></pre>

<p><strong>2 - If you are running Kubernetes locally (like Minikube) the best option is the <code>Nodeport</code> Service Type</strong>: 
It it exposes the service to the Cluster Node( the hosting computer).
Which is safer for testing purposes than exposing the service to the whole internet.</p>

<p>Run: <code>kubectl expose deployment deployment-name --type=NodePort --name=service-name</code></p>

<p><em>Where <code>deployment-name</code> must be replaced by your actual deploy name. and the same goes for the desired <code>service-name</code></em></p>

<p>Bellow are my outputs after exposing an Nginx webserver to the <code>NodePort</code> for your reference:</p>

<pre><code>user@minikube:~$ kubectl get svc
NAME           TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
kubernetes     ClusterIP   10.96.0.1     &lt;none&gt;        443/TCP        4d21h
service-name   NodePort    10.96.33.84   &lt;none&gt;        80:31198/TCP   4s

user@minikube:~$ minikube service list
|----------------------|---------------------------|-----------------------------|-----|
|      NAMESPACE       |           NAME            |         TARGET PORT         | URL |
|----------------------|---------------------------|-----------------------------|-----|
| default              | kubernetes                | No node port                |
| default              | service-name              | http://192.168.39.181:31198 |
| kube-system          | kube-dns                  | No node port                |
| kubernetes-dashboard | dashboard-metrics-scraper | No node port                |
| kubernetes-dashboard | kubernetes-dashboard      | No node port                |
|----------------------|---------------------------|-----------------------------|-----|
user@minikube:~$ curl http://192.168.39.181:31198 
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx!&lt;/title&gt;
...//// suppressed output
&lt;p&gt;&lt;em&gt;Thank you for using nginx.&lt;/em&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
user@minikube:~$
</code></pre>
