Expose a service from mutiple external Ips in kubernetes - docker

I need to expose dashboard service from multiple external ips. In order to expose a service, I used metallb bare metal loadbalancer.
I just manage to expose dashboard service from single external IP. I wonder if it is possible to expose same service from multiple external IPS?

i think you do it using ingress and expose that service as the LoadBalancer so it will be accessible form both load balancer or from both end point.
Ingress will create one Load Balancer and your service also create one load balancer so it will be accessible from both ip

Related

Handle exposing ports on kubernetese in bare metal

I have 1 master and 2 worker on my k8s cluster.It's bare metal and I can't use any of cloud providers. I just can use DNS load balancer. I want to expose valid ports (like 80 and 443) on my nodes because of that I can't use NodePort. What is the best solution?
My only solution was to install Nginx on all of my nodes and proxy ports to my ClusterIp services.I don't know that this is a good solution or not.
Following things that you are doing right :
Cluster IP service - If you don't want to expose your services to be invoked form outside the cluster, CLusterIP is right way instead of NodePort or LoadBalancer.
Following things that you can do:
Create an Ingress Controller and and Ingress resource for your cluster which will listen on port 80 and 443 and proxy the requests to your services according to routes mentioned in the ingress.
You can create inginx-ingress controller using link: https://kubernetes.github.io/ingress-nginx/deploy/
Then create an Ingress resource using link https://kubernetes.io/docs/concepts/services-networking/ingress/
I found the solution. I need to edit /etc/kubernetes/manifests/kube-apiserver.yaml and edit service-node-port-range to 80 to any number that I want. Then declare my ingress service as nodePort.

Forward all service ports to a singe container

I would like to run a container in kubernetes with a static ip. I found out that only a service can provide an ip address.
Is it possible to map a Service to one pod and forward all ports?
A service discovers pods based on labels and selectors. So it is not necessary to use an IP Address to statically reference a pod from a service. However, if you so wish, you can override the autonomy behind this and manually configure your own ClusterIP for the service.
Once the Pod and Service have been created, other pods in your cluster will be able to interact with the pod via the Name of the Service provided they are in the same namespace. If they are not, you will need to pass the FQDN of the service.
If you are trying to access the pod from outside of Kubernetes, then you will need to use a Service with a different type than ClusterIP. For example, a NodePort or a LoadBalancer. Alternatively, if you have an Ingress Controller with a gateway already provisioned you could use that.
With regards to you desire to forward all ports, this is not possible as port declarations in Service files must be statically mapped. It is not currently possible to pass a Port Range but there is a long standing feature request for it.

Pod to Pod communication for a NodePort type service in kubernetes

I have a statfulset application which has a server running on port 1000 and has 3 replicas.
Now, I want to expose the application so I have used type: NodePort.
But, I also want 2 replicas to communicate with each other at the same port.
When I do nslookup in case of NodePort type application it gives only one dns name <svc_name>.<namespace>.svc.cluster.local (individual pods don't get a dns) and the application is exposed.
When I do clusterIP: None I get node specific DNS <statfulset>.<svc_name>.<namespace>.svc.cluster.local but application is not exposed. But both do not work together.
How can I achieve both, expose the same port for inter replica communication and expose same port externally?
LoadBalancer: Exposes the service externally using a cloud provider’s load balancer. NodePort and ClusterIP services, to which the external load balancer will route, are automatically created.

On Premise - Kubernetes External Endpoint for services

We are analyzing the integration of the Kubernetes service in our on premise environment. We have SaaS based services which can be exposed publicly.
We have doubts in setting up the external endpoints for the services. Is there any way to create the external endpoints for the services?
We have tried to setup the ExternalIP parameter in the services with the master node IP address. Not sure this is the correct way. Once we setup the external IP with the master node IP address we are able to access the services.
We have also tried with ingress controllers and also there we can access our services with the IP address of the node where the ingress controllers are running.
For Example :
Public IP : XXX.XX.XX.XX
Ideally, we would map the public IP with the load balancer virtual IP, but we cannot find such a setting in Kubernetes.
Is there any way to address this issue?
My suggestion is to use an Ingress Controller that acts as a proxy for all your services in kubernetes.
Of course your ingress controller has to be somehow exposed to the outside world. My suggestion is to use the hostNetwork setting for the ingress controller pod (this way, the pod will be listening on your host's physical interface, like any other "traditional" service).
A few resources:
Here details on how a pod can be reached from outside your k8s cluster).
Here a nice tutorial on how to setup an ingress controller on k8s.
If you have more than one minion in your cluster, you'll end up having problems with load balancing them. This question can be helpful about that.

Do I require a load balancer for a web service container in google cloud?

I have set up a working web server using google Container Engine. It is a single container running a web service and is accessible from the browser.
The tutorial said to use a load balancer to expose an external IP, which I did.
My question is: Do I have to use a load balancer? or is there another way to get an external IP?
The reason I ask is that the load-balancer looks like it will cost way more than any other part of the set up and I don't actually need to load-balance anything. I used the google pricing calculator to assume this.
You don't HAVE to use a load balancer but your usage of GKE to run one container is not really ideal.
What you could do is use the NodePort type instead of LoadBalancer. That will expose the Node IP addresses with the port of the application that you are running on.
When you use NodePort, it will map a high port range to your port 80 application, for example 31324.
To find out this port, do:
kubectl describe svc wordpress
Find out what the external IP of your GCE machine is and then type this into your browser: http://<GCE-EXTERNAL-IP>:<NodePort>
Don't forget to set firewall rules too.
(you can see why this is not the best use-case for gke)

Resources