<p>I have a VM created in Azure, and I'd like to connect to mariadb service (mariadb.mariadb.svc.cluster.local from cluster nodes)</p>

<p>It's possible to do that using the host name or a private IP?</p>

<p>Thanks!</p>

OnekO
<blockquote>
  <p>It's possible to do that using the host name or a private IP?</p>
</blockquote>

<p>Absolutely! </p>

<p>In Kubernetes, the <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">service</a>  is used to communicate with pods. </p>

<p>The default service type in Kubernetes is ClusterIP</p>

<p>ClusterIP is an <strong>internal</strong> IP address reachable from inside of the Kubernetes cluster only. The ClusterIP enables the applications running within the pods to access the service.</p>

<p>To expose the pods outside the kubernetes cluster, you will need  k8s service of <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer"><code>NodePort</code></a> or <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer"><code>LoadBalancer</code></a> type. </p>

<ul>
<li>NodePort: Exposes the Service on each Node’s IP at a static port (the NodePort). A <code>ClusterIP</code> Service, to which the <code>NodePort</code> Service routes, is automatically created. You’ll be able to contact the NodePort Service, from outside the cluster, by requesting <code>&lt;NodeIP&gt;:&lt;NodePort&gt;</code> .</li>
</ul>

<p>Please note that it is needed to have <strong>external</strong> IP address assigned to one of the nodes in cluster and a Firewall rule that allows ingress traffic to that port. As a result kubeproxy on Kubernetes node (the external IP address is attached to) will proxy that port to the pods selected by the service.</p>

<ul>
<li>LoadBalancer: Exposes the Service externally using a cloud provider’s load balancer. <code>NodePort</code> and <code>ClusterIP</code> Services, to which the external load balancer routes, are automatically created.</li>
</ul>

<p>Alternatively, if you need to access HTTP/S (that is not the case here, but still worth mentioning) it is possible to use <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer"><code>Ingress</code></a></p>

<p>There is a very good article on <a href="http://alesnosek.com/blog/2017/02/14/accessing-kubernetes-pods-from-outside-of-the-cluster/" rel="nofollow noreferrer">acessing Kubernetes Pods from Outside of cluster</a> .</p>

<p>Hope that helps.</p>
