I have the following Ingress definition that works well (I use docker-for-mac):
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: zwoop-ing
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: localhost
http:
paths:
- path: /
backend:
serviceName: posts-api-svc
servicePort: 8083
Where I'm confused is how I would deal with multiple api microservices that I want to expose.
The options that I had in mind:
I assume that multiple ingresses would cost more (?).
For some reason, I have problems using a subpath segment (ingress-nginx).
When I define: - path: /api
in the ingress resource, I receive a 404 on GET request.
It is unclear how to define a subpath (here I use /api, but that would be posts-api, users-api etc).
For a single posts-api, I currently have the following setup:
apiVersion: v1
kind: Service
metadata:
name: posts-api-svc
# namespace: nginx-ingress
labels:
app: posts-api
#rel: beta
#env: dev
spec:
type: ClusterIP
selector:
app: posts-api
# rel: beta
# env: dev
ports:
- protocol: TCP
port: 8083
With a deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: posts-api-deployment
# namespace: nginx-ingress
spec:
replicas: 1
selector:
matchLabels:
app: posts-api
template:
metadata:
labels:
app: posts-api
# env: dev
# rel: beta
spec:
containers:
- name: posts-api
image: kimgysen/posts-api:latest
ports:
- containerPort: 8083
livenessProbe:
httpGet:
path: /api/v1/posts/health
port: 8083
initialDelaySeconds: 120
timeoutSeconds: 1
The health check on the pod works fine for endpoint: /api/v1/posts/health
I assume that multiple ingresses would cost more (?).
When I define: - path: /api in the ingress resource, I receive a 404 on GET request.
This means it's going to the default backend and likely because of this annotation nginx.ingress.kubernetes.io/rewrite-target: /
. Essentially, that's stripping the /api
from your request that is going to your backend. If you want to preserve the path, I suggest you remove the annotation.
You can always check the nginx ingress controller nginx.conf
file with something like:
$ kubectl cp <pod-where-nginx-controller-is-running>:nginx.conf .
$ cat nginx.conf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With