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(/|$)(.*)
`
Related
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]+/
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
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
I have an helm chart serving an Mediawiki using apache. Internally it does so from /wiki.
I'd like to run multiply instances and externally reach it from /something-wiki, /other-wiki and so on.
So in other words I'd like to have my ingress controller react to one path and internally go to another path.
I tried the below but it just sends a 301 (moved permanently) which doesn't work since the folder doesn't exists.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /wiki
name: wiki-environment-erst-env
namespace: wiki
spec:
rules:
- host: aks-dev.something.com
http:
paths:
- backend:
serviceName: erst-wiki-package
servicePort: 80
path: /erst-wiki
tls:
- hosts:
- aks-dev.something.com
secretName: erst-tls-secret
Any ideas?
If I understand correctly, regexp redirection might work. And the wiki configuration should be handled accordingly.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/use-regex: true
name: wiki-environment-erst-env
namespace: wiki
spec:
rules:
- host: aks-dev.something.com
http:
paths:
- backend:
serviceName: erst-wiki-package
servicePort: 80
path: /erst-wiki/.*
tls:
- hosts:
- aks-dev.something.com
secretName: erst-tls-secret
Using the Nginx Ingress Controller, we would like to expose different paths of a Kubernetes service, with different security requirements.
/ is open to the public
/white-list only allows connections from a specific IP Address
/need-key requires an API key
I'm running in AWS EKS. Kubernetes version is as follows:v1.12.6-eks-d69f1b.
If we use Annotations, they apply to the entire service. Ideally I would like to apply an Annotation only to a path.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-myServiceA
annotations:
# use the shared ingress-nginx
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: myServiceA.foo.org
http:
paths:
- path: /
backend:
serviceName: myServiceA
servicePort: 80
- path: /white-list
backend:
serviceName: myServiceA
servicePort: 80
**NEED SOMETHING HERE TO WHITELIST**
- path: /need-key
backend:
serviceName: myServiceA
servicePort: 80
**NEED SOMETHING HERE TO USE API-KEY**
The results I've been having end up applying to all the paths.
I can live without API-Key as I can code that out, but ideally, I'd rather have it managed outside of the container.
Has anyone accomplished this with NGINX Ingress controller?
To apply annotation for each path, you could write one ingress rule for each path you want to apply. Nginx Ingress Controller will collect those ingress rules by itself and apply accordingly.
For example:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-myServiceA-root
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: myServiceA.foo.org
http:
paths:
- path: /
backend:
serviceName: myServiceA
servicePort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-myServiceA-white-list
annotations:
kubernetes.io/ingress.class: "nginx"
ingress.kubernetes.io/whitelist-source-range: X.X.X.X/32
spec:
rules:
- host: myServiceA.foo.org
http:
paths:
- path: /white-list
backend:
serviceName: myServiceA
servicePort: 80
...