Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ingress path does not work #349

Closed
gyliu513 opened this issue Feb 27, 2017 · 12 comments
Closed

Ingress path does not work #349

gyliu513 opened this issue Feb 27, 2017 · 12 comments

Comments

@gyliu513
Copy link
Contributor

I created a ingress service as following:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mynginx
spec:
  rules:
  - host: mynginx.com
    http:
      paths:
      - path: /v1
        backend:
          serviceName: my-nginx
          servicePort: 80
      - path: /v2
        backend:
          serviceName: my-nginx-1
          servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: my-nginx-1-11
  name: my-nginx-1
  namespace: default
spec:
  ports:
  - name: nginx
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: my-nginx-1-11
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: my-nginx
  name: my-nginx
  namespace: default
spec:
  ports:
  - name: nginx
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: my-nginx
  type: ClusterIP
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: my-nginx
  name: my-nginx
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      run: my-nginx
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - image: gyliu/nginxv1:1.0
        imagePullPolicy: IfNotPresent
        name: my-nginx
        ports:
        - containerPort: 80
          protocol: TCP
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: my-nginx-1-11
  name: my-nginx-1-11
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      run: my-nginx-1-11
  template:
    metadata:
      labels:
        run: my-nginx-1-11
    spec:
      containers:
      - image: gyliu/nginxv2:1.0
        imagePullPolicy: IfNotPresent
        name: my-nginx-1-11
        ports:
        - containerPort: 80
          protocol: TCP

Then after the service create finished, I can see the detail of ingress is as following:

[root@bd002 ~]# kubectl get ing mynginx -o yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  creationTimestamp: 2017-02-27T06:23:39Z
  generation: 1
  name: mynginx
  namespace: default
  resourceVersion: "125183"
  selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/mynginx
  uid: 474f67b7-fcb5-11e6-b29b-f2ecb40a350b
spec:
  rules:
  - host: mynginx.com
    http:
      paths:
      - backend:
          serviceName: my-nginx
          servicePort: 80
        path: /v1
      - backend:
          serviceName: my-nginx-1
          servicePort: 80
        path: /v2
status:
  loadBalancer:
    ingress:
    - ip: 9.111.253.118

Then I put 9.111.253.118 mynginx.com to the /etc/hosts on which I will access the services, and then when I access mynginx.com/v1 and mynginx.com/v2, both failed.

Then I check the nginx conf for the ingress controller, found the proxy setting is as following:

location /v2 {






            proxy_set_header Host                   $host;

            # Pass Real IP
            proxy_set_header X-Real-IP              $remote_addr;

            # Allow websocket connections
            proxy_set_header                        Upgrade           $http_upgrade;
            proxy_set_header                        Connection        $connection_upgrade;

            proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Host       $host;
            proxy_set_header X-Forwarded-Port       $server_port;
            proxy_set_header X-Forwarded-Proto      $pass_access_scheme;

            # mitigate HTTPoxy Vulnerability
            # https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx/
            proxy_set_header Proxy                  "";

            proxy_connect_timeout                   5s;
            proxy_send_timeout                      60s;
            proxy_read_timeout                      60s;

            proxy_redirect                          off;
            proxy_buffering                         off;

            proxy_http_version                      1.1;


            proxy_pass http://default-my-nginx-1-80;
        }


        location /v1 {






            proxy_set_header Host                   $host;

            # Pass Real IP
            proxy_set_header X-Real-IP              $remote_addr;

            # Allow websocket connections
            proxy_set_header                        Upgrade           $http_upgrade;
            proxy_set_header                        Connection        $connection_upgrade;

            proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Host       $host;
            proxy_set_header X-Forwarded-Port       $server_port;
            proxy_set_header X-Forwarded-Proto      $pass_access_scheme;

            # mitigate HTTPoxy Vulnerability
            # https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx/
            proxy_set_header Proxy                  "";

            proxy_connect_timeout                   5s;
            proxy_send_timeout                      60s;
            proxy_read_timeout                      60s;

            proxy_redirect                          off;
            proxy_buffering                         off;

            proxy_http_version                      1.1;


            proxy_pass http://default-my-nginx-80;
        }

For the proxy_pass, should not we use absolute path?

I mean seems the proxy should be set as following:

location /v2 {
  ...
  proxy_pass http://default-my-nginx-1-80/;
}

location /v1 {
  ...
  proxy_pass http://default-my-nginx-80/;
}
@aledbf
Copy link
Member

aledbf commented Feb 28, 2017

@gyliu513 proxy_pass http://default-my-nginx-80/; means that you services my-nginx and my-nginx-1 do not have active endpoints or there is no service with that name in port 80.
Please check the ingress logs using kubectl logs <ing pod> and search for my-nginx
What version of the ingress controller are you using?

@gyliu513
Copy link
Contributor Author

Thanks @aledbf , yes, you may see that both of my service my-nginx and my-nginx-1 are using 80, so I can access both services via curl my-nginx and curl my-nginx-1.

The following is the logs from ingress controller:

[root@bd002 ~]# kubectl logs nginx-ingress-lb-amd64-mwk0f --namespace=kube-system | grep my-nginx
W0228 23:26:02.988992       1 controller.go:841] service default/my-nginx does not have any active endpoints
W0228 23:26:02.989015       1 controller.go:841] service default/my-nginx-1 does not have any active endpoints
W0228 23:26:02.989327       1 controller.go:777] upstream default-my-nginx-80 does not have any active endpoints. Using default backend
W0228 23:26:02.989336       1 controller.go:777] upstream default-my-nginx-1-80 does not have any active endpoints. Using default backend

And my ingress version is 0.8.3, any comments?

@aledbf
Copy link
Member

aledbf commented Feb 28, 2017

@gyliu513 please remove name: nginx from the ports. We fixed this issue last week.

@gyliu513
Copy link
Contributor Author

gyliu513 commented Mar 1, 2017

We fixed this issue last week.

So I need to use the latest version ingress? Does there are any link/issue that I can refer to get more detail for what do you fix? @aledbf

@aledbf
Copy link
Member

aledbf commented Mar 1, 2017

@gyliu513
Copy link
Contributor Author

gyliu513 commented Mar 1, 2017

Thanks @aledbf , will try to see if the latest build can help.

But with my current env, after removing the name: nginx, still no lucky.

Seems the ingress has some problems if I define a rule with one host but multiple paths.

LiuGuangyas-MacBook-Pro:~ gyliu$ curl mynginx.com/v2
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.11.10</center>
</body>
</html>
LiuGuangyas-MacBook-Pro:~ gyliu$ curl mynginx.com/v1
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.11.10</center>
</body>
</html>

@aledbf
Copy link
Member

aledbf commented Mar 1, 2017

@gyliu513 right, that output is from one of our nginx behind the ingress controller. Please keep in mind that if youmake a request to mynginx.com/v2 the nginx behind receives the path /v2. Please check the nginx log behind the ingress controller

@gyliu513
Copy link
Contributor Author

gyliu513 commented Mar 1, 2017

@aledbf finally, it is working now after I applied annotations: ingress.kubernetes.io/rewrite-target: / based on kubernetes-retired/contrib#860 , thanks @aledbf for your help!

My whole yaml template:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mynginx
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: mynginx.com
    http:
      paths:
      - path: /v1
        backend:
          serviceName: my-nginx
          servicePort: 80
      - path: /v2
        backend:
          serviceName: my-nginx-1
          servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: my-nginx-1-11
  name: my-nginx-1
  namespace: default
spec:
  ports:
  - name: nginx
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: my-nginx-1-11
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: my-nginx
  name: my-nginx
  namespace: default
spec:
  ports:
  - name: nginx
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: my-nginx
  type: ClusterIP
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: my-nginx
  name: my-nginx
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      run: my-nginx
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - image: gyliu/nginxv1:1.0
        imagePullPolicy: IfNotPresent
        name: my-nginx
        ports:
        - containerPort: 80
          protocol: TCP
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: my-nginx-1-11
  name: my-nginx-1-11
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      run: my-nginx-1-11
  template:
    metadata:
      labels:
        run: my-nginx-1-11
    spec:
      containers:
      - image: gyliu/nginxv2:1.0
        imagePullPolicy: IfNotPresent
        name: my-nginx-1-11
        ports:
        - containerPort: 80
          protocol: TCP

And test result:

LiuGuangyas-MacBook-Pro:~ gyliu$ curl mynginx.com/v1
my-nginx-1427292677-bvl79-v1
LiuGuangyas-MacBook-Pro:~ gyliu$ curl mynginx.com/v2
my-nginx-1-11-1450361824-zmzkw-v2

@chestack
Copy link

chestack commented Jun 6, 2017

came into same problem. we should update online doc of ingress to add "annotations: ingress.kubernetes.io/rewrite-target: /" into example yaml

@gyliu513
Copy link
Contributor Author

gyliu513 commented Jun 6, 2017

@chestack we actually already have document here for multi path.

@RouR
Copy link

RouR commented Mar 8, 2018

@gyliu513 broken link

@CharAct3
Copy link

@gyliu513 broken link

Try this link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants