Connect to cluster service from virtual machine in Azure

3/2/2020

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

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

Thanks!

-- OnekO
azure
azure-aks
kubernetes
virtual-machine

2 Answers

3/3/2020

if your service is of type clusterIP (which is the default) then you can not access this service outside of Kubernetes. You need to change the type of service to NodePort or clusterIP I am not sure kube-proxy can help here or not. this blog well describes all of this

considering you have access to k8s outside, definitely you can access pods outside k8s with help of

  1. kubectl exec get the shell of the running container in k8s
  2. kubectl port-forward maps container port with your local port.
-- Guru
Source: StackOverflow

3/3/2020

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

Absolutely!

In Kubernetes, the service is used to communicate with pods.

The default service type in Kubernetes is ClusterIP

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

To expose the pods outside the kubernetes cluster, you will need k8s service of NodePort or LoadBalancer type.

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

Please note that it is needed to have external 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.

  • LoadBalancer: Exposes the Service externally using a cloud provider’s load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.

Alternatively, if you need to access HTTP/S (that is not the case here, but still worth mentioning) it is possible to use Ingress

There is a very good article on acessing Kubernetes Pods from Outside of cluster .

Hope that helps.

-- Nick
Source: StackOverflow