https://rancher.com/ logo
Title
b

best-wall-17038

09/07/2022, 9:21 AM
In rancher why I can not able to access my frontend app through External-IP?
kubectl get svc -n nginx -o wide                                                                                                                                                                                                                                                                                                                    
NAME                  TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                      AGE   SELECTOR
nginx-nginx-ingress   LoadBalancer   10.43.49.252   192.168.178.38   80:32277/TCP,443:32004/TCP   52d   app=nginx-nginx-ingress
When I added localhost as a host, I can access over localhost but this is not something i wanter
apiVersion: <http://networking.k8s.io/v1|networking.k8s.io/v1>
kind: Ingress
metadata:
  name: {{ include "frontend-service.fullname" . }}
  namespace: comnext
  annotations:
    <http://nginx.ingress.kubernetes.io/service-upstream|nginx.ingress.kubernetes.io/service-upstream>: "true"
    <http://nginx.ingress.kubernetes.io/use-regex|nginx.ingress.kubernetes.io/use-regex>: "true"
    <http://ingress.kubernetes.io/rewrite-target|ingress.kubernetes.io/rewrite-target>: /$1
    <http://nginx.ingress.kubernetes.io/configuration-snippet|nginx.ingress.kubernetes.io/configuration-snippet>: |
      proxy_set_header l5d-dst-override frontend-service.comnext.svc.cluster.local;
      proxy_hide_header l5d-remote-ip;
      proxy_hide_header l5d-server-id;
spec:
  ingressClassName: nginx
  rules:
    - host: localhost
      http:
        paths:
          - backend:
              service:
                name: frontend-service
                port:
                  number: 80
            path: /
            pathType: ImplementationSpecific
m

miniature-advantage-69986

09/07/2022, 3:33 PM
I assume that you have installed the nginx-ingress controller as by default Rancher-Desktop uses "traefik" as the ingress-controller. If you define the host as "frontend-service.localhost" you should be able to access your service from a browser. All FQDNs ending with "*.localhost" do not need DNS entries as these should always be interpreted as IP 127.0.0.1 by the browser, if you use other names you will have to enter these into a DNS Server or in a local "hosts" file. The frontend service on the other hand can access backend services in the same namespace by just using the servicename and does not need to be quailified unless in a different namespace. The DNS lookups are then done inside kubernetes via coredns.
b

best-wall-17038

09/07/2022, 4:47 PM
@miniature-advantage-69986 I could not get %100.. 😞 What you are saying is, use
frontend-service.localhost
as a hostname and rest of the services name should be end with
.localhost
, am I right ? Then can browser/frontend access rest of microservices via their DNS names, am I right ?
m

miniature-advantage-69986

09/08/2022, 5:25 AM
No, i'm afraid i wasn't very clear. If you want to access services fron outside of kubernetes (for example from your browser) you will be doing this through an ingress-contoller and wil need an ingress manifest for each service you wish to access. if you have services in kubernetes that need to communicate with other services in the same cluster, then these can just do so by using te service name. Example: frontend-service can just do something like
curl <http://backend-service>
but if you want to access backend-service from your browser or curl on your windows/mac/linux you would have to setup an ingress with something like host: backend-service.kubernetes.localhost and then you can open http://backend-service.localhost
Sorry, i made a typo. If the ingress definition is host: backend-service.kubernetes.localhost you would open it with the URL http://backend-service.kubernetes.localhost
b

best-wall-17038

09/08/2022, 6:40 AM
@miniature-advantage-69986 its totally clear now.. Is there any other way to achieve this via nginx for instance ?
b

bitter-hairdresser-7812

09/10/2022, 2:29 PM
Check out this article for a very simple example: https://itnext.io/simplest-minimal-k8s-app-tutorial-with-rancher-desktop-in-5-min-5481edb9a4a5
apiVersion: <http://networking.k8s.io/v1|networking.k8s.io/v1>
kind: Ingress
metadata:
  name: jade-shooter
spec:
  rules:
  - host: jade-shooter.rancher.localhost
    http:
      paths:
      - pathType: Prefix
        path: /
        backend:
          service:
            name: jade-shooter-service
            port:
              number: 8080
  tls:
  - hosts:
    - jade-shooter.rancher.localhost