I'm using Kubernetes on Azure cloud, and I have installed zipkin. I already install nginx ingress, and if I use the following host rule, it works fine:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
namespace: nginx-ingress
spec:
- host: zipkin.hostname.com
http:
paths:
- backend:
serviceName: zipkin
servicePort: 9411
But this is not what I want. What I want is something like hostname.com/zipkin.
I tried with this, but I got a 404 error:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
namespace: nginx-ingress
spec:
rules:
- http:
paths:
- path: /zipkin
backend:
serviceName: zipkin
servicePort: 9411
What do I have to do?
Edit: I tried to add the host and after doing a describe command i get this
Name: NAME
Namespace: NAMESPACE
Address:
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
hostname.com
/zipkin zipkin:9411 (10.244.0.63:9411)
EDIT: I solved my issue adding a rewrite rule annotation
nginx.org/rewrites: >
serviceName=zipkin rewrite=/;
First, previous answer is wrong, you don't need to specify host
it is not mandatory unless you want to set up a DNS.
Second, the backend zipkin
requires the /zipkin
URI to respond right? If this is the case, then the rewrite annotation is removing the URI. So you would need to change your yaml like this to pass /zipkin
to your backend.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
kubernetes.io/ingress.class: nginx
namespace: nginx-ingress
spec:
rules:
- http:
paths:
- path: /zipkin
backend:
serviceName: zipkin
servicePort: 9411
It's because you haven't mentioned the host
here:
spec:
rules:
- host: hostname.com // here
http:
paths:
- path: /zipkin
backend:
serviceName: zipkin
servicePort: 9411
Just to clarify the OP problem.
There are different ingress Controllers
Note:
When you create an ingress, you should annotate each ingress with the appropriate ingress.class to indicate which ingress controller should be used if more than one exists within your cluster.
If you do not define a class, your cloud provider may use a default ingress controller.
Ideally, all ingress controllers should fulfill this specification, but the various ingress controllers operate slightly differently.
Using this annotation:
nginx.org/rewrites: >
serviceName=zipkin rewrite=/;
It looks like you are using NGINX Ingress Controller provided by nginxinc.
You can find more information about Rewrites Support for NGINX Ingress Controller provided by nginxinc here.
example:
nginx.org/rewrites: "serviceName=service1 rewrite=rewrite1[;serviceName=service2 rewrite=rewrite2;...]"
It's different from the kubernetes community at kubernetes/ingress-nginx repo. Different ingress controllers have different configs and annotations.
So for this example:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.org/rewrites: "serviceName=my-nginx rewrite=/"
name: test-ingress
namespace: default
spec:
rules:
- host: hostname.com
http:
paths:
- backend:
serviceName: my-nginx
servicePort: 80
path: /zipkin
status:
loadBalancer:
ingress:
- ip: xx.xxx.xxx.xx
Test it:
curl -vH 'Host:hostname.com' xx.xxx.xxx.xx/zipkin
* Connected to xx.xxx.xxx.xx (xx.xxx.xxx.xx) port 80 (#0)
> GET /zipkin HTTP/1.1
> Host:hostname.com
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.17.5
< Date: Mon, 28 Oct 2019 12:21:48 GMT
< Content-Type: text/html
< Content-Length: 612
< Connection: keep-alive
< Last-Modified: Tue, 22 Oct 2019 14:30:00 GMT
< ETag: "5daf1268-264"
< Accept-Ranges: bytes
<
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>