not able to load static content in ingress resource - kubernetes

I am facing a wierd issue... I am trying to invoke active mq webui using ingress resources... page is loading but static content is not loading and it is saying not found....
Here is my ingress resource.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: myingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- http:
paths:
- path: /(.*)\.(jpg|jpeg|png|gif|ico|js|css|csv|json)$
backend:
serviceName: nginx-static
servicePort: 80
- path: "/"
backend:
serviceName: service1
servicePort: 8233
- path: "/test"
backend:
serviceName: server2
servicePort: 9002
http:
paths:
- path: "/admin"
backend:
serviceName: activemq-server
servicePort: 80
Kindly help how static content will be loaded....

Add to your ingress configuration file following annotations:
nginx.ingress.kubernetes.io/add-base-url: "true"
nginx.ingress.kubernetes.io/rewrite-target: "specify rewriting rule here"
Similar problem you can find here: ingress-static-contetnt.

Related

EKS Ingress ALB add HTTP listener for some services and HTTPS for others

I have the following ingress.yaml file
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: in
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/load-balancer-attributes: idle_timeout.timeout_seconds=600
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/certificate-arn: xxxx
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
spec:
rules:
- http:
paths:
- path: /api/bulk-api/*
backend:
serviceName: dg-bulk-api
servicePort: 5000
- path: /api/adjuster-selection
backend:
serviceName: dg-adjuster-selection
servicePort: 5050
- path: /api/cockpit/*
backend:
serviceName: dg-cockpit
servicePort: 5050
- path: /api/regression/*
backend:
serviceName: dg-regression
servicePort: 5005
- path: /api/lp/task-details*
backend:
serviceName: lp-task-detail
servicePort: 5050
- path: /api/tool-setup/*
backend:
serviceName: dg-tool-setup
servicePort: 5000
- path: /api/guideline/*
backend:
serviceName: dg-guideline
servicePort: 5050
- path: /*
backend:
serviceName: dg-ui
servicePort: 80
The above mentioned yaml creates an ALB with listener at 80 and 443 added for all the routes. However, I want listener 80 for for all routes except dg-ui service and 443 for dg-ui service only. Let me know how can this be done.
I have been able to solve the issue. Thought it would be helpful for everyone.
Updated my ALB Ingress Controller to v2.1. Instructions can be found at: AWS LoadBalancer Controller
Create separate Ingress Yaml for Http and Https listener rules.
Add annotation: alb.ingress.kubernetes.io/group.name: my-team.awesome-group to both Ingress. This would create 2 Ingress and attach the rules to 1 common ALB. More on this annotation can be found here: IngressGroups
If you want to ensure some urls working with just https or http you need to define ingress.kubernetes.io/ssl-redirect: "true" annotation for http or ingress.kubernetes.io/ssl-redirect: "false" for using just http. The fact is that declared annotation affect whole path that you define in ingress object that is why you need to seperate Ingress definitions like below examples. So that for http you need to use like below yaml;
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: https-ingress
annotations:
ingress.kubernetes.io/ssl-redirect: "true"
spec:
tls:
- hosts:
- example.com
secretName: tls-secret
rules:
- host: example.com
http:
paths:
- path: /secured
backend:
serviceName: my-service
servicePort: 8080
For just http you need to use like below yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: http-ingress
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- host: example.com
http:
paths:
- path: /unsecured
backend:
serviceName: my-service
servicePort: 8080

nginx-ingress path based angular application

I have an angular application which is dockerized using nginx-alpine as base image. My infra is hosted on AKS cluster version 1.18.14 . And nginx-ingress to route traffic to pods k8s.gcr.io/ingress-nginx/controller:v0.44.0 . Below is my Ingress
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- http:
paths:
- path: /?(.*)
backend:
serviceName: portal
servicePort: 80
When I hit the application with ip-address/ application loads .
But If I want to add path to it with below nginx-ingress app doesn't load.
- path: /myportal(/|$)(.*)
backend:
serviceName: my-portal
servicePort: 80
WHen I hit ip-address/myportal app doesn't load. What changes should I make
It looks like there is a mistake in your yaml config.
It should be:
paths:
- backend:
serviceName: my-portal
servicePort: 80
path: /myportal(/|$)(.*)
instead of:
- path: /myportal(/|$)(.*)
backend:
serviceName: my-portal
servicePort: 80
Make sure the indentation are in place and syntax is correct. Use this example as a reference.

Ingress making react app not to route correctly

I have a react app that works fine. However after putting it in k8s and installing ingress, whenever I refresh a page i get the following although it just refreshed the page. How do I correct this?
Here is a snippet of my yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- http:
paths:
- path: /api/auth/*
backend:
serviceName: um-service
servicePort: 5001
- path: /api/profile/*
backend:
serviceName: um-service
servicePort: 5001
- path: /api/pass/*
backend:
serviceName: um-service
servicePort: 5001
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: admin-ingress
annotations:
kubernetes.io/ingress.class: nginx
# nginx.ingress.kubernetes.io/use-regex: "true"
# nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /admin
# pathType: Exact
backend:
serviceName: admin-service
servicePort: 4000
I must say I have challenges hitting the admin backend. It just doesn't load i.

Ingress routing to different services and with different paths to same service

I have the following ingress config:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
pathType: Exact
backend:
serviceName: web-service
servicePort: 5000
paths:
- path: /api/tasks/.*
pathType: Prefix
backend:
serviceName: tasks-service
servicePort: 5004
paths:
- path: /api/.*
pathType: Prefix
backend:
serviceName: um-service
servicePort: 5001
I'm intending to load the frontend by default then, use the other paths for loading other services. I would like to get the total tasks count from /api/tasks/total_count and raise new task from /api/tasks/raise. At the same time, I would like to login using /api/auth/login/ and view other users with /api/users/list both served with the um-service.
The above configuration only returns the default path of the last service which is the um-service.
How do I configure so that web loads by default, then either /api/auth/login or /api/users/list are routed to the um-service and /api/tasks/ is also routed to the tasks service? Kindly advice
If I understand you correctly, you want to achieve that result:
$ curl <MY_DOMAIN>/api/auth/login
um-service
$ curl <MY_DOMAIN>/api/users/list
um-service
$ curl <MY_DOMAIN>/api/tasks/
tasks-service
$ curl <MY_DOMAIN>/
web-service
You almost did everything right, but paths should only be given once
Try this configuration:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: web-service
servicePort: 5000
- path: /api/tasks/.*
backend:
serviceName: tasks-service
servicePort: 5004
- path: /api/.*
backend:
serviceName: um-service
servicePort: 5001

Kubernetes nginx ingress rewrite issue

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: default
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: $2
spec:
rules:
- host: hostname.com
http:
paths:
- path: /
backend:
serviceName: frontend
servicePort: 80
- path: /api/v1(/|$)(.*)
backend:
serviceName: backend
servicePort: 80
What I am trying to accomplish here is:
hostname.com/api/v1/anyurl should become hostname.com/anyurl when it goes to the backend.
hostname.com/anyurl should remain hostname.com/anyurl and go to the frontend.
The /api/v1 rewrite seems to work, but any urls going to the frontend gets rewrited to /.
What I need is the rewrite rule to only apply to the /api/v1 path
I guess this should work for you -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: default
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: $1
spec:
rules:
- host: hostname.com
http:
paths:
- path: /(.*)
backend:
serviceName: frontend
servicePort: 80
- path: /api/(.*)
backend:
serviceName: backend
servicePort: 80
I have just edited this, it works for me, please check for this. I guess we can troubleshoot