<p>There is a lot of sources that clarify how to connect into the cluster. But when searching for information about how to connect from inside the cluster to outside the search results are polluted with the opposite information.</p>
<p>I want to connect my custom service that is running inside the cluster to my keycloack that is outside of the cluster on my local machine. There is no option of running keycloak inside the cluster. I am using Docker desktop for Mac to run kubernetes.</p>

<blockquote>
<p>There is no option of running keycloak inside the cluster.</p>
</blockquote>
<p>Not sure may you have checked or not, you can run the <strong>keycloak</strong> on the Kubernetes.</p>
<p>You can refer my Github repo to get YAML files and deployment keycloak on Kubernetes : <a href="https://github.com/harsh4870/Keycloack-postgres-kubernetes-deployment" rel="nofollow noreferrer">https://github.com/harsh4870/Keycloack-postgres-kubernetes-deployment</a></p>
<p>Generally, you can use the <strong>external</strong> service, if you are diverting the traffic out of the cluster.</p>
<p>If you are running on a Public K8s cluster on any cloud provider service will be directly able to access the external service over IP without external service creation.</p>
<p><strong>Example</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: local-host
spec:
    type: ExternalName
    externalName: 192.168.0.1
</code></pre>
<p>If you don't want to pass the IP in external service you can give any domain name map details in <strong>/etc/hosts</strong> files too. <a href="https://kubernetes.io/docs/concepts/services-networking/service/#externalname" rel="nofollow noreferrer">ref doc</a></p>
<p>Now if you Keycloak is running on Host machine (localhost) you can use the IP directly.</p>
<p>If you are using the <strong>minikube</strong> you can use the <code>host.minikube.internal</code> as host. <a href="https://minikube.sigs.k8s.io/docs/handbook/host-access/" rel="nofollow noreferrer">ref doc</a></p>
<pre><code>host.minikube.internal:&lt;Port of keycloak&gt;
</code></pre>
