Im Kubernetes, I have a load balancer, and 2 web apps (with names "UI" and "Kuard") that are both publicly available through services and ingress rules similar to:
Kuard Service:
apiVersion: v1
kind: Service
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |xxx
creationTimestamp: "2022-01-17T15:44:30Z"
labels:
app: kuard
app.kubernetes.io/managed-by: pulumi
name: mykuard
namespace: nginx-test-frwjnfp0
resourceVersion: "975"
uid: 819d94ca-b63d-44d5-9af9-a83da3f4bbd8
spec:
clusterIP: 10.3.250.8
clusterIPs:
- 10.3.250.8
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- port: 8080
protocol: TCP
targetPort: http
selector:
app: kuard
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
Kuard Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: | xxx
kubernetes.io/ingress.class: nginx
pulumi.com/autonamed: "true"
creationTimestamp: "2022-01-17T15:44:42Z"
generation: 2
labels:
app: kuard
app.kubernetes.io/managed-by: pulumi
name: kuard-tuy3sb0v
namespace: nginx-test-frwjnfp0
resourceVersion: "13091"
uid: 4d14f3fc-d116-4233-a717-c38d92741139
spec:
rules:
- host: kuard.xxx.com
http:
paths:
- backend:
service:
name: mykuard
port:
name: http
path: /
pathType: ImplementationSpecific
status:
loadBalancer:
ingress:
- ip: xxx
As you can see for now I can access the Kuard app by going to kuard.xxx.com where xxx is the public LB IP.
Currently I am able to navigate to the "Kuard" app from the "UI" app by hardcoding kuard.xxx.com in my UI app. This is stupid because I'm using the WWW address rather than using the internal cluster address.
Which URL (and ingress?) can I use in order to open the "Kuard" app in the browser from the "UI" app based on its internal cluster address, rather than the WWW URL?
I tried hardcoding http://mykuard:80 in the "UI" web app because the service name for the "Kuard" app is "mykuard", but i'm definitely missing something.
CodePudding user response:
What you want is not possible.
When accessing a service from a browser, you are making request from outside your cluster. For this you need external IP.
The internal cluster address (<service-name>:<port>) is for internal communication only (e.g. pod to pod) , and is resolved by your internal DNS, to which your browser does not have access.
