I have a Kubernetes cluster with 2 containers running in a single workload.
One container is running a Flask server application and the other is running an angular application. I need to have this pod set up in a way where both applications can communicate with each other within the localhost. I need the angular container which is exposed in port 4200 to communicate with the unexposed flask server which is on port 5000. I am stuck when it comes to having these containers communicate within the pod.
Rather than localhost (127.0.0.1), make sure your flask server is reachable via any local IP, that is, app.run(host='0.0.0.0').
You should be able to communicate with each other using localhost:<port-number> as all containers in a Kubernetes pod share the same network namespace.
Related
I have a Kubernetes cluster with an on-demand auto-scaler to provide easily scaleable VM instances.
I want to provide SSH access (port 22) to the machines created within them behind a single ingress controller.
Example:
ssh poda.example.com:22 it should provide an ssh connection to pod A
ssh podb.example.com:22 it should provide an ssh connection to pod B
Another Example of UDP: There are two deployments of Redis within the cluster in two different namespaces. within the cluster, we are able to separate them using their service name. but outside the cluster we are not able to separate them
Expected Behaviour
redis-staging.example.com:6379 should connect to Redis in staging namespace
redis-prod.example.com:6379 it should connect to Redis in production namespace
I was using the Nginx ingress controller to open the port via a load-balancer to provide ssh access using the https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/ documentation.
Challenge is that this directly bypasses the requirement of the sub-domain part and connects one port to one pod only. even a non-existing sub-domain can connect to the one pod linked to the port exposed.
How can I implement the desired behavior with Nginx or any other Ingress controller?
I need to connect a service running in a local container inside Docker on my machine to a database that's running on a Kubernetes cluster.
Everything I found on port forwarding allowed me to connect my machine to the cluster, but not the local container to the cluster (unless I install kubectl on my container, which I cannot do).
Is there a way to do this?
https://www.telepresence.io/ is what you're looking for. It will hook into the cluster network like a VPN and patch the services so traffic will get routed through the tunnel.
I noticed when accessing the Kubernetes Service, the host ip is ignored by the kubernetes.
For example: I have 3 kubernetes workers, hostIP1, hostIP2 and hostIP3, on each worker, i create a pod, with label: app = test. In each pod, it just simple runs python -m SimpleHTTPServer 32000, I then create a service to expose port: 32000 so that it can be accessed outside the cluster.
But when I access http://hostIP1:32000, the traffic is actually routed to any of the hosts, hostIP1, hostIP2 and hostIP3
Is there a way to only let Kubernetes forward traffic to hostIP1 when accessing http://hostIP1:32000?
Thanks
You can't do that. If your pods have the same label, they are going to be selected by the same service, and every time you hit that service it is going to balance the load among the backends it has, which are your pods.
To do what you want, you have to create 3 different services, to point each service to its own backend.
I have a requirement that the server that is running inside one of my container in a k8s cluster should be able to reach a server that is running in some other machine (currently its in AWS).Now the problem is that both the server (in AWS & Kubernetes Cluster) should be able to reach each other.
My server in AWS is not able to ping my Server running in Kubernetes Cluster.
Is that possible? Can we do it ?
Yes you can use ingress-nginx to create publicly reachable services ingress-nginx
If you want to do it manually you can setup load balancers that map to specific ip ranges for your nodes. This is for ssh traffic.
yes you can use ingress kubernetes object it will create publicly reachable services.
Mainly if you are using aws or digital-ocean and you will use ingress it will make load balancer (ELB or ALB) and make public service and you can access server running inside kubernetes
By manually also you can do it just simply use kubernetes service and expose it using load balancer and NODE port
https://kubernetes.io/docs/concepts/services-networking/service/
I am trying to connect to a Docker container on Google Container Engine(GKE) from my local machine through the internet by TCP protocol. So far I have used Kubernetes services which gives an external IP address, so the local machine can connect to the container on GKE using the service. When we create a service, we can specify only one port and cannot specify the port range. Please see the my-ros-service.yaml below. In this case, we can access the container by 11311 port from outside of GCE.
However, some applications that run on my container expose dynamic ports to connect to other applications. Therefore I cannot determine the port number that the application uses and cannot create the Kubernetes services before I run the application.
So far I have managed to connect to the container by creating many services which have different port while running the application. But this is not a realistic way to solve the problem.
My question is that:
How to connect to the application that exposes dynamic ports on Docker container from outside of the GCE by using Kubernetes service?
If possible, can we create a service which exposes dynamic port for incoming connection before running the application which runs on the container?
Any advice or information you could provide would be greatly appreciated.
Thank you in advance.
my-ros-service.yaml
kind: Service
apiVersion: v1beta1
id: my-ros-service
port: 11311
selector:
name: my-ros
containerPort: 11311
createExternalLoadBalancer: true
I don't think there is currently a better solution than what you are doing. There is already a related issue, kubernetes issue 1802, about having multiple ports per service. I mentioned your requirements on that issue. You might want to follow up there with more information about your use case, such as what program you are running (if it is publicly available), and whether the dynamic ports come from a specific contiguous range.