Is it possible to have placeholders in kong plugin k8s? - kubernetes

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: kong-ingress-test
annotations:
kubernetes.io/ingress.class: "kong-ingress"
konghq.com/strip-path: "true"
namespace: test
spec:
rules:
- host: test.com
http:
paths:
- backend:
serviceName: test
servicePort: 8080
path: /path/test/{id1}/{id2}/
I am wondering if is possible to have a path set like this in the plugin /path/test/{id1}/{id2}/

Solution for path was using regex
/path/test/[a-fA-F0-9]+/[a-fA-F0-9]+/

Related

not able to create the rule for the ingress controller

What am I going wrong in the below query?
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /nginx
backend:
serviceName: nginx
servicePort: 80
The error I am getting:
error validating "ingress.yaml": error validating data: [ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field "servicePort" in io.k8s.api.networking.v1.IngressBackend]; if you choose to ignore these errors, turn validation off with
--validate=false
Ingress spec has changed since updated to v1. Try:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /nginx
pathType: ImplementationSpecific
backend:
service:
name: nginx
port:
number: 80
According to this documentation you need to change ServiceName and ServicePort.
Each HTTP rule contains (...) a list of paths (for example, /testpath), each of which has an associated backend defined with a service.name and a service.port.name or service.port.number. Both the host and path must match the content of an incoming request before the load balancer directs traffic to the referenced Service.
Here is your yaml file with corrections:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /nginx
backend:
service:
name: nginx
port:
number: 8080
ServiceName and ServicePort no keywords are available like that in v1 .
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /nginx
backend:
service:
name: nginx
port:
number: 8080
service name and service port syntax is incorrect. Follow the below sample
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx-example
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80

Rewrite rule for nginx-ingress in Kubernetes

I am struggling with making a rewrite/redirect rule on nginx-ingress on Kubernetes.
According to the doc https://kubernetes.github.io/ingress-nginx/examples/rewrite/ it says it is possible with the annotation "nginx.ingress.kubernetes.io/rewrite-target", but unable to implement on my ingress. Maybe I am doing it wrong.
An example, portion of nginx-ingress yaml file.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
example.com/deployment-name: frontend-page
example.com/ingress-hostnames: www.example.com
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
serviceName: frontend-page
servicePort: 8080
path: /front(/|$)(.*)
Tried another way around as well but no luck:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
example.com/deployment-name: frontend-page
example.com/ingress-hostnames: www.example.com
nginx.ingress.kubernetes.io/rewrite-target: /shop
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
serviceName: frontend-page
servicePort: 8080
path: /
I want to redirect any traffic to the page www.example.com/front/checkdomain to www.example.com/checkdomain. I want to remove that "front" path comes in between.
try this with an updated API version, hope your ingress supports networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
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(/|$)(.*)
Example : https://kubernetes.github.io/ingress-nginx/examples/rewrite/#examples
The solution was
Changing from:
nginx.ingress.kubernetes.io/rewrite-target: /$2
To:
nginx.ingress.kubernetes.io/rewrite-target: /$2/
So the yaml looks like:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
example.com/deployment-name: frontend-page
example.com/ingress-hostnames: www.example.com
nginx.ingress.kubernetes.io/rewrite-target: /$2/
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
serviceName: frontend-page
servicePort: 8080
path: /front(/|$)(.*)

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

How to create redirection url

I would to build following an service deployed to kubernetes to be accessed using an ingress object.
I would like to use https://mylocation.com/myprogram/doc to access the app but only https://mylocation.com/myprogram/doc/ works.
I have created the following entry in my yaml
# -----------------
# Ingress object
# -----------------
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: myapp-ingress
namespace: documentation
annotations:
kubernetes.io/ingress.class: nginx
#Default is 'true'
spec:
tls:
- hosts:
- mylocation.com
rules:
- host: mylocation.com
http:
paths:
- backend:
serviceName: myapp-service
servicePort: 80
path: /myapp/doc
- backend:
serviceName: myapp-service
servicePort: 80
path: /myapp/doc/(.*)
I have created the ingress object kubectl apply -f filename
When I browse http://mylocation.com//myapp/doc, I get HTTP ERROR 404
When I browse http://mylocation.com//myapp/doc/, It works
Can someone help me to get http://mylocation.com//myapp/doc working?
Thanks for your help.
Make sure to place appropriate regex
# -----------------
# Ingress object
# -----------------
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: myapp-ingress
namespace: documentation
annotations:
kubernetes.io/ingress.class: nginx
#Default is 'true'
spec:
tls:
- hosts:
- mylocation.com
rules:
- host: mylocation.com
http:
paths:
- backend:
serviceName: myapp-service
servicePort: 80
path: /myapp/doc(/|$)(.*)
`

How to use rewrite in traefik

I am using abc.com/foo and it is working fine, but whatever url like abc.com/foo/account-login I need to redirect to abc.com/account-login and it is not working. Please let me know how can I set rewrite or any other annotatios in traefik.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
traefik.frontend.rule.type: PathPrefixStrip
kubernetes.io/ingress.class: traefik
name: dev-ingress
namespace: dev
spec:
rules:
- host: abc.com
http:
paths:
- backend:
serviceName: dev-service
servicePort: http
path: /foo
status:
loadBalancer: {}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/rewrite-target: /account-login
name: dev-ingress
namespace: dev
spec:
rules:
- host: abc.com
http:
paths:
- backend:
serviceName: dev-service
servicePort: http
path: /foo
status:
loadBalancer: {}
It depends on your back-and configuration but probably you can try:
remove traefik.frontend.rule.type: PathPrefixStrip" and set path: /
Please let me know if its helps