Your template is right, are you using ingress controller?
Here want to show you an example as what I did:
1) start the ingress controller.
2) Create an deployment, service and ingress service.
```
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
---
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: NodePort
---
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
```
After the objects create finished, then check ingress service.
```
[root@bd002 kq]# kubectl get ing -o yaml
apiVersion: v1
items:
- apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/rewrite-target: /
creationTimestamp: 2017-03-09T02:41:23Z
generation: 1
name: mynginx
namespace: default
resourceVersion: "625497"
selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/mynginx
uid: e22b0f6f-0471-11e7-8035-f2ecb40a350b
spec:
rules:
- host: mynginx.com
http:
paths:
- backend:
serviceName: my-nginx
servicePort: 80
path: /v1
status:
loadBalancer:
ingress:
- ip: 9.111.253.118
kind: List
metadata: {}
resourceVersion: ""
selfLink: ""
```
On the host where you want to access the nginx service, add `9.111.253.118
mynginx.com` to your /etc/hosts.
Then `curl`.
This is my output:
```
[root@bd002 kq]# curl mynginx.com/v1
my-nginx-1427292677-mzcdz-v1
```
If you still have question, please check the nginx.conf in your nginx
controller to check the proxy policy there, there should be some
configuration as this:
```
upstream default-my-nginx-80 {
least_conn;
server 10.1.37.206:80 max_fails=0 fail_timeout=0;
}
location ~* /v1 {
...
rewrite /v1/(.*) /$1 break;
rewrite /v1 / break;
proxy_pass http://default-my-nginx-80;
}
```
On Thu, Mar 9, 2017 at 10:31 AM, <[email protected]> wrote:
> I appreciate the suggestion! I have tried the "rewrite" annotation, and
> the result is the same. Also I am not using nginx.
>
> Is my url request format (as I put in my previous post, just attaching the
> path to the end of the ip address) correct? I am at a loss. Ingress would
> be really useful if I could actually get this to work.
>
>
> On Wednesday, March 8, 2017 at 6:04:07 PM UTC-8, Guangya Liu wrote:
> > Please make sure adding ` ingress.kubernetes.io/rewrite-target: /`
> annotation to your service profile, otherwise, nginx proxy will not work.
> >
> >
> > ```
> >
> > apiVersion: extensions/v1beta1
> > kind: Ingress
> > metadata:
> > name: mynginx
> > annotations:
> > ingress.kubernetes.io/rewrite-target: /
> > spec:
> > rules:
> > - host: test.jizhihuwai.com
> > http:
> > paths:
> > - path: /v1
> > backend:
> > serviceName: my-nginx
> > servicePort: 80
> > - path: /v2
> > backend:
> > serviceName: my-nginx-1
> > servicePort: 80
> > ```
> >
> >
> > There is also some configuration here: https://github.com/
> kubernetes/ingress/blob/master/controllers/nginx/configuration.md#rewrite
> >
> >
> > On Thu, Mar 9, 2017 at 9:42 AM, <[email protected]> wrote:
> > I am trying to use an Ingress with path-based routing, similar to the
> following example:
> >
> >
> >
> > apiVersion: extensions/v1beta1
> >
> > kind: Ingress
> >
> > metadata:
> >
> > name: path-based-ingress
> >
> > spec:
> >
> > rules:
> >
> > - http:
> >
> > paths:
> >
> > - path: /foo
> >
> > backend:
> >
> > serviceName: http-svc
> >
> > servicePort: 80
> >
> >
> >
> > But when I make a request to the host ip address with a path (i.e. curl
> -i http://1.2.3.4/foo), I get a "404 - Not Found" response. If I change
> the path in the ingress config file to just "/" and run "curl -i
> http://1.2.3.4/", everything works fine; I get a valid response.
> >
> >
> >
> > Thanks in advance for any help!
> >
> >
> >
> > --
> >
> > You received this message because you are subscribed to the Google
> Groups "Kubernetes user discussion and Q&A" group.
> >
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected].
> >
> > To post to this group, send email to [email protected].
> >
> > Visit this group at https://groups.google.com/group/kubernetes-users.
> >
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Kubernetes user discussion and Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/kubernetes-users.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/kubernetes-users.
For more options, visit https://groups.google.com/d/optout.