I have application "test.abc.com". I want to transfer request between different service.
Example or Expected output
when user hit test.abc.com --> it will go to abc-demo-frontend-external service
when user hit test.abc.com/main.js --> it will go to abc-demo-frontend service
I added below code but it is not working
current output
when user hit test.abc.com or test.abc.com/main.js both request going to abc-demo-frontend ? why ?
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-demo-frontend-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: "test.abc.com"
http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: abc-demo-frontend
port:
number: 80
- path: /
pathType: ImplementationSpecific
backend:
service:
name: abc-demo-frontend-external
port:
number: 80
any idea..?
You can try
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-demo-frontend-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: "test.abc.com"
http:
paths:
- path: /(.+\.(css|js))
pathType: ImplementationSpecific
backend:
service:
name: abc-demo-frontend
port:
number: 80
- path: /
pathType: ImplementationSpecific
backend:
service:
name: abc-demo-frontend-external
port:
number: 80
Related
i cannot get pth base nginx routing working. I got host based working. Here is the yaml config
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
name: ingress-resource-3
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-deploy-main
port:
number: 80
- path: /blue
pathType: Prefix
backend:
service:
name: nginx-deploy-blue
port:
number: 80
- path: /green
pathType: Prefix
backend:
service:
name: nginx-deploy-green
port:
number: 80
however host routing works below
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-resource-2
spec:
ingressClassName: nginx
rules:
- host: testingress.cluster.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-deploy-main
port:
number: 80
- host: blue.testingress.cluster.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-deploy-blue
port:
number: 80
- host: green.testingress.cluster.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-deploy-green
port:
number: 80
any idea why path base routing is not working?
also I dont see my hostname when i try to get ingress
[rke#k8gui ingress-demo]$ kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-resource-3 nginx * 80 11m
My ingress file like this and I cannot get my resources when it comes up multiple paths
And my ingress file like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite: /
spec:
ingressClassName: nginx
rules:
- host: foo.test.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service1
port:
number: 80
- path: /service2
pathType: Prefix
backend:
service:
name: service2
port:
number: 80
Is there anybody can help me find solutions?
I had installed an ran a kubernetes cluster with an nginx ingress earlier this year. Though it had little issues, it worked fine. For the ingress, I used the tag
apiVersion: networking.k8s.io/v1beta1
However, I have recently installed the latest version of (kubernetes 1.22) which only allows for
apiVersion: networking.k8s.io/v1
The problem i'm having is using my old yaml configuration with the new format.
My yaml file looks like this:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: dev-ingress
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/websocket-services : "chatserver"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS"
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- http:
paths:
- path: /api/auth/
pathType: Prefix
backend:
serviceName: um-service
servicePort: 5001
- path: /api/system/*
pathType: Prefix
backend:
serviceName: system-service
servicePort: 5002
- path: /api/news/*
backend:
serviceName: news-service
servicePort: 5003
- path: /api/tasks/*
# pathType: Prefix
backend:
serviceName: tasks-service
servicePort: 5004
- path: /api/chats/
pathType: Prefix
backend:
serviceName: chatserver
servicePort: 5500
- path: /
backend:
serviceName: web-service
servicePort: 5000
my new manifest looks like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: dev-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /api/auth/
pathType: Prefix
backend:
service:
name: um-service
port:
number: 5001
- path: /api/system/*
pathType: Prefix
backend:
service:
name: system-service
port:
number: 5002
- path: /api/chats/
pathType: Prefix
backend:
service:
name: chatserver
port:
number: 5050
- path: /
pathType: Prefix
backend:
service:
name: web-service
port:
number: 5000
ingressClassName: nginx
How do I convert this to use the new apiVersion: networking.k8s.io/v1 tag?
Fortunately there isn't too much difference between the API versions in terms of the YAML. Here's an example of networking.k8s.io/v1 from the Kubernetes Docs.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
The main change for you would have to do with the how the backend blocks are done. For example:
backend:
serviceName: tasks-service
servicePort: 5004
would need to become:
backend:
service:
name: "tasks-service"
port:
number: 5004
I have read in ingress-nginx documentation that the rewrite is being performed thanks to an annotation like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: rewrite
namespace: default
spec:
rules:
- host: rewrite.bar.com
http:
paths:
- backend:
serviceName: http-svc
servicePort: 80
path: /something(/|$)(.*)
I have a case where I have multiple hosts and I want URL rewriting for some particular paths only:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
name: ingress
spec:
rules:
- host: somehost.westeurope.cloudapp.azure.com
http:
paths:
- path: /rest-smtp-sink # I want to rewrite this path
pathType: Prefix
backend:
service:
name: rest-smtp-sink-svc
port:
number: 80
- path: /backend # This one too
pathType: Prefix
backend:
service:
name: server-svc
port:
number: 80
- path: / # But not this one
pathType: Prefix
backend:
service:
name: client-svc
port:
number: 80
However, the annotation seems to be global. How do I enable URL rewriting for some paths only?
I managed to get the desired result with this configuration:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: ingress
spec:
rules:
- host: somehost.westeurope.cloudapp.azure.com
http:
paths:
- path: /rest-smtp-sink(/|$)(.*)
pathType: Prefix
backend:
service:
name: rest-smtp-sink-svc
port:
number: 80
- path: /backend(/|$)(.*)
pathType: Prefix
backend:
service:
name: server-svc
port:
number: 80
- path: /()(.*)
pathType: Prefix
backend:
service:
name: client-svc
port:
number: 80
As the nginx.ingress.kubernetes.io/rewrite-target annotation is global, I've used /$2 as the rewrite target and /()(.*) as a noop for the root path.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-world-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/add-base-url: "true"
nginx.ingress.kubernetes.io/use-regex: "true"
cert-manager.io/cluster-issuer: letsencrypt
spec:
tls:
- hosts:
- mints.cf
secretName: tls-secret
rules:
- host: mints.cf
http:
paths:
- path: /amq(/|$)(.*)
pathType: Prefix
backend:
service:
name: activemq-artemis
port:
number: 8161
- path: /*(/|$)(.*)
pathType: Prefix
backend:
service:
name: mints-ui
port:
number: 3000
- path: /nginx(/|$)(.*)
pathType: Prefix
backend:
service:
name: nginx-deployment
port:
number: 80
- path: /kafka(/|$)(.*)
pathType: Prefix
backend:
service:
name: kafka-manager
port:
number: 9000
- path: /kibana(/|$)(.*)
pathType: Prefix
backend:
service:
name: kibana
port:
number: 5601
I Deployed some React JS application into my aks cluster by using deploymentyaml file, and created an Ingress Controller for exposing service with public IP and DNS configuration. Ingress Working other services but it is showing blank page for ReactJS applications. screenshot from browser for reference
Can anyone help me out from this issue?