Ingress on root colliding with ingress on path - kubernetes-helm

I have two containers - one that is a static page in nginx and second one that is react app.
I would like to serve static page on / and react app on /app
Currently the problem is that when I enter / I have redirect on /app
Excerpt of helm for static page:
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/app-root: /
paths:
- /
Excerpt of helm for react app:
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/app-root: app/
paths:
- /app
kubectl describe ingress:
Name: app
Namespace: prod
Address:
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
example.com
/app app:http (10.244.2.52:80)
Annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/app-root: app/
Name: static-page
Namespace: prod
Address:
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
example.com
/ static-page:80 (10.244.2.40:80)
Annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/app-root: /

You might try to use multipath configuration within one ingress object without nginx.ingress.kubernetes.io/app-root: annotation, it works for me in similar scenario:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
name: example
spec:
rules:
- http:
paths:
- backend:
serviceName: static-page
servicePort: 80
path: /
- backend:
serviceName: app
servicePort: 80
path: /app

Related

Is there a way to see why I am not seeing any events when I try to use an Ingress with GKE?

I have the following ingress...
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: core-ingress
namespace: earth
annotations:
kubernetes.io/ingress.global-static-ip-name: "core-proxy-static-ip"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: core-ingress
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: core-proxy-service
port:
number: 80
I have used kubectl exec to make sure the service itself is running and listening on port 80 so I know core-proxy-service is working. When I try to install the ingress it never gets and IP and the events show nothings...
Name: core-ingress
Namespace: earth
Address:
Default backend: default-http-backend:80 (10.109.128.78:8080)
Rules:
Host Path Backends
---- ---- --------
*
/ core-proxy-service:80 (10.109.128.132:80)
Annotations: kubernetes.io/ingress.global-static-ip-name: core-proxy-static-ip
nginx.ingress.kubernetes.io/rewrite-target: /
Events: <none>
Since there are no events I figure something must have happened and that is why I am not getting an IP but how would I be able to debug to figure out what?
NAMESPACE NAME CLASS HOSTS ADDRESS PORTS AGE
earth core-ingress core-ingress * 80 3m33s
Update
If I revert back to
defaultBackend:
service:
name: core-proxy-service
port:
number: 80
Everything works what am I missing?
Try something like :
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-myservicea
annotations:
kubernetes.io/ingress.global-static-ip-name: "core-proxy-static-ip"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /
backend:
serviceName: core-proxy-service
servicePort: 80
Ref doc : https://kubernetes.github.io/ingress-nginx/user-guide/basic-usage/

Ingress uses wildcard, although I didn't specify that

I have the following ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
namespace: apps
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/custom-http-errors: '404'
spec:
tls:
- hosts:
- mywebsite.com
secretName: my-secret-tls
rules:
- host: mywebsite.com
- http:
paths:
- path: /api/events
pathType: ImplementationSpecific
backend:
service:
name: my-events-api-svc
port:
number: 80
When I kubectl describe this ingress, I see the following
Name: my-ingress
Namespace: apps
Address: 52.206.112.10
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
TLS:
my-secret-tls terminates mywebsite.com
Rules:
Host Path Backends
---- ---- --------
*
/api/events my-events-api-svc:80 (10.244.4.145:4000,10.244.5.118:4000)
Annotations: kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/custom-http-errors: 404
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal UPDATE 9s (x7 over 153m) nginx-ingress-controller Ingress apps/my-ingress
The issue is that the specified path doesn't work, I'm getting 404. I noticed that in the output above, there is a * under the Host. My other ingresses are configured pretty much the same (only have different paths set), and there is no * in the kubectl describe output. Instead, in my other ingresses the proper Host - "mywebsite.com" - is shown.
The output above also has some error (<error: endpoints "default-http-backend" not found>), but I see it as well in my other ingresses (that do work).
What could be the problem?
Its your indentation, please check official example
spec:
rules:
- host: hello-world.info
http:
paths:
Try
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
namespace: apps
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/custom-http-errors: '404'
spec:
tls:
- hosts:
- mywebsite.com
secretName: my-secret-tls
rules:
- host: mywebsite.com
http:
paths:
- path: /api/events
pathType: ImplementationSpecific
backend:
service:
name: my-events-api-svc
port:
number: 80

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 whitelist only one path in kubernetes nginx ingress controller

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
...

Kubernetes ingress block in creating state

I have deployed an app with Google Kubernetes Engine. All function works perfectly but I have a strange problem. If I check the status in Google cloud console the ingress is always in creating phase.
You can see it in image:
Have you some suggestion to resolve it?
Thanks
[EDIT]
kubectl describe ingress:
Name: ++++++-nginx-ingress
Namespace: ++++++
Address:
Default backend: default-http-backend:80 (10.4.0.4:8080)
Rules:
Host Path Backends
---- ---- --------
++++++-back.*******.net
++++++-nginx-np:80 (<none>)
++++++.*******.net
++++++-front-np:80 (<none>)
Annotations:
ingress.kubernetes.io/backends: {"k8s-be-30141--93abcf3e6a0e0671":"HEALTHY","k8s-be-32338--93abcf3e6a0e0671":"HEALTHY","k8s-be-32589--93abcf3e6a0e0671":"HEALTHY"}
ingress.kubernetes.io/url-map: k8s-um-++++++-++++++-nginx-ingress--93abcf3e6a0e0671
kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{"kubernetes.io/ingress.allow-http":"false","kubernetes.io/ingress.global-static-ip-name":"++++++-nginx-ingress-ip"},"labels":{"app":"++++++-nginx-ingress"},"name":"++++++-nginx-ingress","namespace":"++++++"},"spec":{"rules":[{"host":"++++++-back.*******.net","http":{"paths":[{"backend":{"serviceName":"++++++-nginx-np","servicePort":80}}]}},{"host":"++++++.*******.net","http":{"paths":[{"backend":{"serviceName":"++++++-front-np","servicePort":80}}]}}]}}
kubernetes.io/ingress.allow-http: false
kubernetes.io/ingress.global-static-ip-name: ++++++-nginx-ingress-ip
Events:
<none>
YAML file:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ++++++-nginx-ingress
labels:
app: ++++++-nginx-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: ++++++-nginx-ingress-ip
kubernetes.io/ingress.allow-http: "false"
namespace: ++++++
spec:
rules:
- host: ++++++-back.++++++.net
http:
paths:
- backend:
serviceName: ++++++-nginx-np
servicePort: 80
- host: ++++++.++++++.net
http:
paths:
- backend:
serviceName: ++++++-front-np
servicePort: 80
Checking your output I can see that the loadbalncer is not created or not getting your static IP ++++++-nginx-ingress-ip normally after the Spec.Backend
status:
loadBalancer:
ingress:
- ip: xx.xx.xx.xx
On thing the Annotation kubernetes.io/ingress.allow-http: "false" is used when TLS for the ingress is configured.
Another thing you may check if the Add-on for L7 HTTP load balancing is Enabled by default when creating the cluster is enabled