I have created a 2 node Kubernetes cluster on Azure.
Then I deploy my service using the following yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-st
labels:
app: cloud-test
spec:
replicas: 3
selector:
matchLabels:
app: cloud-test
template:
metadata:
labels:
app: cloud-test
spec:
containers:
- name: cloud-test
image: test:latest
imagePullPolicy: Always
ports:
- containerPort: 3046
---
apiVersion: v1
kind: Service
metadata:
name: service-st
spec:
type: ClusterIP
selector:
app: cloud-test
ports:
- protocol: TCP
port: 3046
targetPort: 3046
I am using cluster IP, so I created an ingress for this :
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: k8s-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/proxy-body-size: 100m
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /v1(/|$)(.*)
pathType: Prefix
backend:
service:
name: service-st
port:
number: 3046
i also chekc this box :
Now, if I access the address of the nginx in services (External Ip), i get 404 from nginx. Also,if i access ip/v1 , get 404 again.
Am I missing anything here?
2
Answers
There your ingress class is mentioned. you are using the ALB controller but using the nginx class it’s not working.
Nginx ingress controller there then you can use ingressClassName as nginx.
For ref if you refer this article Nginx example : https://learn.microsoft.com/en-us/azure/aks/ingress-basic?tabs=azure-cli
ALB controller might be using Gateway API, so may not need to create ingress you will be creating resources like deployment i guess. i have not used AKS & it’s ingress controller.
read more about Ingress Vs Gateway diff : https://medium.com/google-cloud/kubernetes-ingress-vs-gateway-api-647ee233693d
Ref AKS ingress : https://learn.microsoft.com/en-us/azure/application-gateway/ingress-controller-install-existing
You may try to start simple, making sure you access your service when connecting to your virtual host without any rewrite target and when it works build up the rewrite.
(!) Use a host name, not an IP address, for example by configuring your
hosts
file if you do not have a domain registration to use.For example: