I'm trying to set up a cluster like this:
+--------------+ +---------------+
| | | |
| Express API | | Front End |
| | | Static Assets |
| | | |
+------+-------+ +--------+------+
^ ^
| |
| |
+------+-------------------+------+
| /api/.. / |
| Ingress |
+--------------+------------------+
^
+
Internet
For now I'm doing this on Minikube.
I've looked at these two guides:
https://kubernetes.io/docs/concepts/services-networking/ingress/
https://medium.com/@Oskarr3/setting-up-ingress-on-minikube-6ae825e98f82
In the second guide - he exposes his deployments with NodePort services, and then configures his ingress to use those services.
This also means - that those services can be just accessed directly via IP address.
However, my understanding is that that's not necessary - you can just declare an unexposed service, and let ingress expose them. (similar to how they've done it in this official documentation).
ie:
kind: Service
apiVersion: v1
metadata:
name: template-frontend-service
labels:
app: template
spec:
selector:
app: template
type: frontend
ports:
- protocol: TCP
port: 80
targetPort: 80
kind: Service
apiVersion: v1
metadata:
name: template-api-service
labels:
app: template
spec:
selector:
app: template
type: api
ports:
- protocol: TCP
port: 80
targetPort: 3001
But this is where I'm running in to an issue:
Ingress:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: template-ingress
labels:
app: template
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
backend:
serviceName: default-http-backend
servicePort: 80
rules:
- host: template.example.com
http:
paths:
- path: /
backend:
serviceName: template-frontend-service
servicePort: 80
- path: /api
backend:
serviceName: template-api-service
servicePort: 80
I get:
503 Service Temporarily Unavailable nginx/1.13.12
On the other hand, if I just expose my deployments directly with:
kubectl expose deploy template-api --type=NodePort
kubectl expose deploy template-frontend --type=NodePort
(this will give me two services template-api
and template-frontend
)
then this configuration will work:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: template-ingress
labels:
app: template
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
backend:
serviceName: default-http-backend
servicePort: 80
rules:
- host: template.example.com
http:
paths:
- path: /
backend:
serviceName: template-frontend
servicePort: 80
- path: /api
backend:
serviceName: template-api
servicePort: 80
What am I missing here?