I have created and deployed an application on ICP 2.1. Have exposed NodePort as my service. Iam able to navigate to the url from the Nodeport. How do i go to a specific path on the url directly from the Nodeport. Iam using yaml file to create the deployment and service. Where should i specify the path??
How do i go to a specific path on the url directly from the Nodeport
The short version is that you don't, since a NodePort is merely an exposure of an existing port: from a Service.
The medium length version is that using an ingress controller (such as the "default" nginx one) would allow you to add an app-root to the Ingress resource, and then use the NodePort belonging to the ingress controller rather than the NodePort of the upstream Service itself. I'm pretty sure all of the ingress controllers support that kind of behavior since it's a fairly common scenario.
The long version is that you can manually put something like nginx or haproxy between your Service and the upstream Pod to artificially inject a URI prefix, with the disadvantage that if you wish to do that more than once, you'd be better off using an Ingress resource so that functionality is handled for you in a standardized way.
Related
Currently, we are using a loadbalancer type srevice for routing external requests to one of our pods.
We would like to move this to an ingress type service ( there is already an external load balancer setup along with an ingress controller - and we do have other pods configured to receive external requests via this ingress controller)
What we have now is the below url, used by the clients to connect externally:
ws://streamevents.app.com:7080/stomp
wss://streamevents.app.com:7443/stomp
We would like to move it to
ws://streameventsv2.app.com/stomp
wss://streameventsv2.app.com/stomp
This way, we can free up the loadbalancer IP and do not need specific ports. We do want to support both url's together for a while - since clients are already connecting to the old one. How could we achieve this?
Options I can think of (we use helm):
Create a separate chart and deployment with the Ingress service - the old one still uses the LoadBalancer
Same chart - expose the service both ways (is this really possible?)
Change the current one to Ingress - and somehow also make sure we route requests to the old url to the new ingress (how?)
Or any other possible approaches?
I'm guessing you own the helm chart and hence you can make changes to it. If so, you can expose your service both using Ingress and LoadBalancer service. You don't need any changes in any other resources in the helm chart other than adding an Ingress resource. You can remove the LoadBalancer object when you can stop supporting it.
Hello Kubernetes Experts,
Trying to get a better understanding here.
I have created a deployment with a regular deployment yaml and service yaml
The service is node port, I then created a ingress and pointed the service
Tried to access the service and it works as expected on the default port of 80 on nginx ingress.
Next created the same deployment and service file. The only exception here was insted of node port is chose ClusterIP. Created a Ingress and pointed the service.
Tried to access the service and it simply fails with the nginx home page and does not do any routing to my application.
I understand that nodeport is what exposes the application to the external world.
But then I'm using Ingress to attain the same functionality.
Do we really need to set the service as node port even if we use Ingress???
Or is something terribly wrong with my yaml files. I tried reading about it and could not get any relevant explanation.
Thank you,
Anish
First, the Service and Ingress resources works a bit different across cloud providers. E.g. on Google Cloud Platform and AWS, you need to use a NodePort service when using Ingress but on e.g. OpenShift ClusterIP is working.
Mostly, the reason is that the Load Balancer is located outside of your cluster (this is not the case on the OpenShift environment where I work).
From Google Cloud documentation, use NodePort for load balancing but ClusterIP if your load balancer is "container native".
In the Service manifest, you must use type: NodePort unless you're using container native load balancing. If using container native load balancing, use the type: ClusterIP.
This is more a design question than an issue. We have deployed in our company our own Kubernetes infrastructure and we are trying to use ingresses and NGINX ingress controller to externally expose our services, but since it is not a cloud environment such as GCP or AWS, we can't use service type "LoadBalancer". Should we just expose our ingress controller through a service type "NodePort"? Is that the normal way to go for production environments (non-cloud)?
From what I've read in another post, one suitable recommendation is to use NodePort, and manually point yet another external load balancer to the port on your Kubernetes nodes.
It just seems that exposing the ingress controller through this mechanism is somehow not very practical or robust (e.g. you don’t know what port your service is going to be allocated, and the port might get re-allocated at some point, etc.)
Is there any other mechanism maybe to expose the ingress controller to the external world?
The Loadbalancer service approach is one way to do it but behind it it's nothing more than a nodeport on the cluster.
Even if you use a service that create a LB on cloud provider, the LB needs to have a target port to communicate with the cluster.
When using a nginx-ingress that will mostly handle web requests, it's common usage to put an ingress in front of a nodeport service.
So with this I think using NodePort services is a good idea to do what you want ;)
This is my opinion, I'm interested if anyone else has another way to do it.
You can specify the port via nodePort in the service. Then it would not be random.
I have a Kubernetes services that I would like to be accessible from outside the cluster.
I've setup Traefik and have created an Ingress file for that service and am able to go to 'somemadeupdomain.com' and access the service fine. (Having locally added a line in my hosts file).
However my question is with the service type, I've currently set as ClusterIP. I can access the service fine, so is it fine to continue to use that or should I use NodePort.
Of course if I use NodePort I'm aware that when doing minikube service list I'll get a specific URL created by Kubernetes to access that service, but I feel I don't need to do that as I have that ingress file?
Any explanation would be appreciated.
Thanks
As you are using ingress already it does not make much sense to use NodePort. As you already have a way to access your application. Its totally fine to have a service type you need at service level that you need for the internal access(within Kubernets) purpose.
Ingress will redirect your external traffic to your service within the cluster, so ClusterIP is a good choice. No need to use NodePort.
From Documentation
Ingress, added in Kubernetes v1.1, exposes HTTP and HTTPS routes from
outside the cluster to services within the cluster
all
I knew well about k8s' nodePort and ClusterIP type in services.
But I am very confused about the Ingress way, because how will a request come into a pod in k8s by this Ingress way?
Suppose K8s master IP is 1.2.3.4, after Ingress setup, and can connect to backend service(e.g, myservice) with a port(e.g, 9000)
Now, How can I visit this myservice:9000 outside? i.e, through 1.2.3.4? As there's no entry port on the 1.2.3.4 machine.
And many docs always said visit this via 'foo.com' configed in the ingress YAML file. But that is really funny, because xxx.com definitely needs DNS, it's not a magic to let you new-invent any xxx.com you like be a real website and can map your xxx.com to your machine!
The key part of the picture is the Ingress Controller. It's an instance of a proxy (could be nginx or haproxy or another ingress type) and runs inside the cluster. It acts as an entrypoint and lets you add more sophisticated routing rules. It reads Ingress Resources that are deployed with apps and which define the routing rules. This allows each app to say what the Ingress Controller needs to do for routing to it.
Because the controller runs inside the cluster, it needs to be exposed to the outside world. You can do this by NodePort but if you're using a cloud provider then it's more common to use LoadBalancer. This gives you an external IP and port that reaches the Ingress controller and you can point DNS entries at that. If you do point DNS at it then you have the option to use routing rules base on DNS (such as using different subdomains for different apps).
The article 'Kubernetes NodePort vs LoadBalancer vs Ingress? When should I use what?' has some good explanations and diagrams - here's the diagram for Ingress: