I have a single service running on a NodePort service. How do i use ingress to access multiple services.
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth
spec:
replicas: 1
selector:
matchLabels:
app: auth
template:
metadata:
labels:
app: auth
tier: backend
track: dev
spec:
containers:
- name: auth
image: [url]/auth_app:v2
ports:
- name: auth
containerPort: 3000
apiVersion: v1
kind: Service
metadata:
name: auth
spec:
selector:
app: auth
tier: backend
ports:
- protocol: TCP
port: 3000
targetPort: auth
type: NodePort
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
spec:
backend:
serviceName: auth
servicePort: 8080
I followed step by step from the this repo. I could not get it working for my port config. I'm a beginner and would like some resources for the same.
Try these manifests and remember to deploy an Ingress Controller (I usually use traefik, here some instructions to set it)
service.yml
: I changed NodePort to ClusterIP (the default, you can remove the line)
apiVersion: v1
kind: Service
metadata:
name: auth
spec:
selector:
app: auth
tier: backend
ports:
- protocol: TCP
port: 3000
targetPort: auth
type: ClusterIP
ingress.yml
: (I set port to 3000, your service port)
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
spec:
backend:
serviceName: auth
servicePort: 3000
Your service is running in port 3000 but your Ingress routing rule is matching to port 8080. It will probably work if you just change the servicePort to 3000 in the backend section of your Ingress resource definition.
I'd suggest making sure it works with NodePort first before trying Ingress. I suggest this because I notice your Service only specifies values for port and targetPort but not nodePort. If you do not specify a nodeport value, you will get a random port number. As you want to use ingress with NodePort service type, the random port number should not matter.
For NodePort tutorials you could start with https://medium.com/@markgituma/kubernetes-local-to-production-with-django-2-docker-and-minikube-ba843d858817 as I notice you've tagged your post with django
For nginx ingress you could see https://cloud.google.com/community/tutorials/nginx-ingress-gke but you might want to find something specific to your cloud platform if you're not using gke
It is best to start with one service but to understand how this can work for multiple services you could have a look at the fanout ingress example in the docs https://kubernetes.io/docs/concepts/services-networking/ingress/#simple-fanout