caddyserver / ingress

WIP Caddy 2 ingress controller for Kubernetes
Apache License 2.0
620 stars 70 forks source link

Cannot map IngressController to Ingress #241

Closed hxjo closed 1 month ago

hxjo commented 1 month ago

Hello,

First of all, my apologies if the problem here is dumb, I'm very new to Kubernetes. I am trying to setup a simple ingress from a domain to a service, and for some reason it does not seem to work.

cat deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: helloworld
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        image: k8s.gcr.io/echoserver:1.4
        ports:
        - containerPort: 808
cat service.yaml
apiVersion: v1
kind: Service
metadata:
  name: helloworld-service
spec:
  selector:
    app: helloworld
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
cat ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: helloworld-ingress
  annotations:
    kubernetes.io/ingress.class: caddy
spec:
  ingressClassName: caddy
  rules:
  - host: **MASKED**
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: helloworld-service
            port:
              number: 8080
kubectl get svc -n caddy-system
NAME                             TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                      AGE
caddy-caddy-ingress-controller   LoadBalancer   10.43.83.220   **MASKED**   80:30354/TCP,443:31216/TCP   15m

NSLOOKUP on the domain does point to the hostname -I ip on the VPS, which is also referenced as externalIP on the caddy ingress controller.

Caddy ingress server does seem to read the ingress:

{"level":"info","ts":1718608105.6925824,"caller":"controller/action_ingress.go:46","msg":"Ingress created (default/helloworld-ingress)"}

[!NOTE]
When I try with the nginx ingress controller from taken fromhttps://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml (referencing the right externalIP too) (and by switching spec.ingressClassName to nginx in the Ingress), I can curl without issue.

Yet any curl on the hostname results in 404, and no log from the ingress controller.

Would any of you have any idea of what might be causing this ? Have I missed something ?

I am not on a managed kubernetes, I am on a private VPS.

I am using k3s.

If you need any more information to answer the question, please go for it.

Thank you very much for your time, have a nice day. Thanks a lot to the contributors of this project.

hxjo commented 1 month ago

I just tried with the /kubernetes/sample examples and the issue persists:

kubectl get pods
NAME                        READY   STATUS    RESTARTS   AGE
example1-5689599f5b-wrjbw   1/1     Running   0          3m30s
example2-76c8998db8-2gk79   1/1     Running   0          3m28s
kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.43.0.1      <none>        443/TCP    18h
example1     ClusterIP   10.43.65.204   <none>        8080/TCP   3m23s
example2     ClusterIP   10.43.69.103   <none>        8080/TCP   3m21s
kubectl get deployments
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
example1   1/1     1            1           3m58s
example2   1/1     1            1           3m56s
kubectl get ingress
NAME      CLASS    HOSTS                                                         ADDRESS   PORTS   AGE
example   <none>   example1.kubernetes.localhost,example2.kubernetes.localhost             80      4m16s
kubectl get configmap
NAME               DATA   AGE
kube-root-ca.crt   1      2m39s

I still have the logs

{"level":"info","ts":1718623344.3641746,"caller":"controller/action_ingress.go:55","msg":"Ingress updated (default/example)"}

Yet all curl, from the same machine this time, fail

curl example1.kubernetes.localhost/hello2
404 page not found
curl example1.kubernetes.localhost/hello1
404 page not found
curl example2.kubernetes.localhost/hello1
404 page not found
curl example2.kubernetes.localhost/hello2
404 page not found
hxjo commented 1 month ago

I got it working, it seems that:

Thanks again to the contributors of this project, who did an amazing job ❤️