Openshift communication Services - kubernetes

In Openshift I have two services that I need to communicate with each other, I was wondering if you know a way to do that without exposing both microservices.
Example:
(via public endpoint) (exposed) (non public service)
User-request ----------> Service A ----------> Service B
Service A needs to request an endpoint on service B and for that, I am using DNS but to do that I need to expose Service B.
There is any way to do this scenario without exposing service B?
To expose Service A I run the command: "oc expose service/ServiceA"

When you create a Service of type ClusterIP you can directly talk to that service using its DNS name and that Service is available within the cluster. The default DNS name for these services is my-svc.my-namespace.svc.cluster.local.
When using oc expose service you are creating a "Route" that will then make a Service available externally (not what you want in this case).

Related

Does API gateways such as Zuul or Ngnix require backend services to be exposed externally as well?

We are trying to figure out a microservice architecture where we have an API Gateway (Zuul in this case), now all the services that Zuul is redirecting requests to would also need to be exposed externally? It seems counter intuitive as all these services can have private/local/cluster access and gateway is the one that should be externally exposed. Is this correct assessment? In what scenarios would you want these backend services to be exposed externally?
-----
|-----
Normally, you would not expose your backend services externally. The gateway (or the ingress) serves as the external gateway and proxies the requests to the internal network.
I am familiar with one use case where I expose some services directly: I do not want to expose some admin services running on my cluster to the external world, but I want to expose them to my VPN, so I have an ingress forwarding traffic between the external network and the cluster, and nodePort services that expose admin apps to my VPN.

expose pgbouncer service to external clients

I am trying to implement pgbouncer on k8s, using a helm chart created deployment,service…now how do I expose the service to outside world? Not much familiar with k8s networking, tried to create an ingress resource and it created an elb in aws…how do I map this elb to the service and expose it?
the service is created with type ClusterIP…the service is a tcp service i.e. not http/https application (edited)
The helm chart used is - https://github.com/futuretechindustriesllc/charts/tree/master/charts/pgbouncer
Ingresses are only used for HTTP and friends. In this case what you want is probably a LoadBalancer type service. That will make a balancer fabric and then expose it via an ELB.

In Rancher 2.0 Kubernetes, ClusterIP mode service is not served in round robin fashion without Loadbalancer ingress

What I have:
I have created one Kubernetes cluster using single node Rancher 2.0 deployment. which has 3 etcd, control nodes & 2 worker nodes attached to cluster.
What I did:
I deployed one API gateway to this cluster & one express mydemoapi service (no db) with 5 pods on 2 nodes on port 5000, which I don't want to expose publicly. So, I just mapped that service endpoint with service name in API gateway http:\\mydemoapi:5000 & it was accessible by gateway public endpoint.
Problem statement:
mydemoapi service is served in random fashion, not in round robin, because default setting of kube-proxy is random as per Rancher documentation Load balancing in Kubernetes
Partial success:
I created one ingress loadbalancer with Keep the existing hostname option in Rancher rules with this URL mydemoapi.<namespace>.153.xx.xx.102.xip.io & attached this service to ingress, it is served in round robin fashion, but having one problem. This service was using xip.io with public ip of my worker node & exposed publicly.
Help needed:
I want to map my internal clusterIP service into gateway with internal access, so that it can be served to gateway internally in round robin fashion and hence to gateway public endpoint. I don't want to expose my service publicly without gateway.
Not sure which cloud you are running on, but if you are running in something like AWS you can set the following annotation to true on your Service definition:
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
Other Cloud providers have similar solutions and some don't even have one. In that case, you will have to use a NodePort service and redirect an external load balancer such as one with haproxy or nginx to forward traffic to that NodePort
Another option is to not use an Ingress at all if you want to do round robin between your services is to change your kube-proxy configs to use either the old namespace proxy mode or the more enhanced ipvs proxy mode.

Consuming RESTful services orchestrated by Kubernetes

How do you consume a service that is being orchestrated by Kubernetes?
What does the calling statement look like.
When consuming a normal RESTful web service, you might use RestTemplate (for Java) and specify the URL.
How does this differ when Kubernetes creates and destroys occurrences of the service?
Internally, use kubernetes service of ClusterIp type (can also be headless). Externally use service of NodePort or LoadBalancer type to expose your application directly, or Ingress (assuming you have ingress controller deployed/available) to define HTTP(S) based routing from external HTTP(S) level loadbalancer by vhost/path.

Kubernetes services within cluster

I am trying to set up a conventional web app with a database in Kubernetes. I have accomplished it by configuring 2 services and 2 deployments - one for the app and one for the database. Now I would like to make my database accessible only from the app pods, ie not expose it to outside world like a service. Is it possible using only Kubernetes configuration?
There are following ways to expose the pods.
purpose is inter-service communication
Internally expose
service type=clusterIP
Headless-service clusterIP: None is used for database pods
Sometimes you don’t need or want load-balancing and a single service IP. headless-services
Externally expose
Exposing service to the customers.
service type=NodePort or type=LoadBalancer