Skip to content

Tailscale Operator creates Ingress in k8s but doesn't route traffic #10910

Closed

Description

@theelderbeever

What is the issue?

I followed the docs here to add the kubernetes operator to a cluster of mine. I then set a few applications up to use the ingressClassName: tailscale to test access via my tailnet. Unfortunately, all the domains for the ingresses that are create just return 404 Page Not Found.

In my tailscale namespace There is a an operator pod as well as a pod for the ingress ie: ts-nginx-ingress-z5c9l-0.

In said pod I see logs

│ 2024/01/20 20:57:19 magicsock: disco: node [aUfAn] d:f7a13c677130fc87 now using 76.155.93.114:5816 mtu=1360 tx=07fc22e9dac4 │
│ 2024/01/20 20:57:30 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 20:58:15 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 20:58:19 magicsock: disco: node [aUfAn] d:f7a13c677130fc87 now using 192.168.1.189:41641 mtu=1360 tx=99cdae0cb6f3 │
│ 2024/01/20 20:59:00 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 20:59:45 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 21:00:30 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 21:01:15 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 21:02:00 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 21:02:45 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 21:03:30 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 21:04:16 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn │
│ 2024/01/20 21:04:26 magicsock: disco: node [aUfAn] d:f7a13c677130fc87 now using 76.155.93.114:5816 mtu=1360 tx=fca36f890f27 │
│ 2024/01/20 21:04:26 magicsock: disco: node [aUfAn] d:f7a13c677130fc87 now using 192.168.1.189:41641 mtu=1360 tx=303f562206c3 │
│ 2024/01/20 21:05:01 Accept: TCP{100.118.164.53:53976 > 100.118.231.82:443} 40 tcp non-syn

For ingress I see
image

Below are some machines from my account. beeverdam-0 is the actual computer that is running the kubernetes cluster and has a tailscale client on it as well (I have tried turning this off and checking connection with no success).
image

Additionally, the client I am connecting from is using these settings
image

Steps to reproduce

Setup the tailscale operator per the instructions here.

Deploy a service with an ingressClassName: tailscale

Attempt to navigate to the hostname.

Are there any recent changes that introduced the issue?

Brand new deployment

OS

Linux

OS version

Ubuntu 22.04

Tailscale version

Docker 1.56.1

Other software

  • Pihole as local DNS server (I have tried turning off blocking with this)
  • MagicDNS (with/without local nameserver override)
  • Tailscale client on the same computer running the k8s cluster with the operator.

Bug report

BUG-4237683ac2539c453394f0ddf2e234c514776edd66759ecefb91dcc33d7d5eda-20240120211555Z-b55e1a030a645759

Activity

  1. irbekrm commented on Jan 20, 2024

    @irbekrm
    Contributor

    Hi @theelderbeever

    Deploy a service with an ingressClassName: tailscale

    Could you please clarify- do you mean that you created an Ingress resource or a Service? Could you perhaps paste in the Ingress resource (or the Service) ?

  2. theelderbeever commented on Jan 20, 2024

    @theelderbeever
    Author

    @irbekrm My apologies... Created an Ingress resource.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{},"name":"nginx-ingress","namespace":"default"},"spec":{"ingressClassName":"tailscale","rules":[{"host":"default-nginx-ingress-ingress.tail5ec3.ts.net","http":{"paths":[{"backend":{"service":{"name":"nginx-service","port":{"number":80}}},"path":"/","pathType":"Prefix"}]}}]}}
      creationTimestamp: "2024-01-20T20:26:50Z"
      finalizers:
      - tailscale.com/finalizer
      generation: 3
      name: nginx-ingress
      namespace: default
      resourceVersion: "15193555"
      uid: 2cbcde8c-1bdc-4835-ac5f-ebb0aa32e7ed
    spec:
      ingressClassName: tailscale
      rules:
      - host: default-nginx-ingress-ingress.tail5ec3.ts.net
        http:
          paths:
          - backend:
              service:
                name: nginx-service
                port:
                  number: 80
            path: /
            pathType: Prefix
    status:
      loadBalancer:
        ingress:
        - hostname: default-nginx-ingress-ingress.tail5ec3.ts.net
          ports:
          - port: 443
            protocol: TCP
  3. theelderbeever commented on Jan 20, 2024

    @theelderbeever
    Author

    FWIW nslookup returns the right ip address on the network for both the short name and fqdn.

    ❯ nslookup default-nginx-ingress-ingress
    Server:         100.100.100.100
    Address:        100.100.100.100#53
    
    Name:   default-nginx-ingress-ingress.tail5ec3.ts.net
    Address: 100.118.231.82
  4. irbekrm commented on Jan 21, 2024

    @irbekrm
    Contributor

    Thanks for the additional info.

    So the Service is nginx? From the first look it seems to me that it might be either between our proxy and the backend or on our proxy when determining the backend handler.

    There should be a Statefulset created in tailscale namespace with a single Pod with named something like ts-default-nginx-ingress-ingress.. and there also should be a similarly named Secret.
    You should be able to see the backend address that proxy will be using under serve-config key in that Secret i.e

    kubectl view-secret -n tailscale <secret-name> serve-config | jq -r '.'
    {
      "TCP": {
        "443": {
          "HTTPS": true
        }
      },
      "Web": {
        "${TS_CERT_DOMAIN}:443": {
          "Handlers": {
            "/": {
              "Proxy": "http://<nginx-service-ip>:80/"
            }
          }
        }
      }
    }
    
    

    Could you try to exec to the proxy Pod and see if you can reach the backend paths that you are trying to reach using the proxy address in the serve-config? You should be able to apk add curl in the proxy pod.

  5. theelderbeever commented on Jan 21, 2024

    @theelderbeever
    Author

    @irbekrm So it looks like handlers isn't even being populated.

    ❯ kubectl view-secret -n tailscale ts-nginx-ingress-z5c9l-0 serve-config | jq -r '.'
    {
      "TCP": {
        "443": {
          "HTTPS": true
        }
      },
      "Web": {
        "${TS_CERT_DOMAIN}:443": {
          "Handlers": {}
        }
      }
    }

    The service it is supposed to be pointing to though is reachable from the ts-nginx-ingress-z5c9l-0 pod in the tailscale namespace.

    / # curl nginx-service.default.svc.cluster.local
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
    html { color-scheme: light dark; }
    body { width: 35em; margin: 0 auto;
    font-family: Tahoma, Verdana, Arial, sans-serif; }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    
    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
    
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>
    / #
  6. irbekrm commented on Jan 21, 2024

    @irbekrm
    Contributor

    So it looks like handlers isn't even being populated

    Hi, thanks for that additional info! Looks like something went wrong at the point when the operator should have populated the serve config.
    Could you please paste in the backend Service?
    Also, are there any events on the tailscale Ingress? If there aren't any, would you be able to recreate the Ingress and check if our operator writes any events to it?
    (This is the part of code that deals with writing the serve config, I'm just trying to understand what went wrong, I suspect that maybe it wasn't able to get the Service at the time and didn't retry or similar).

  7. theelderbeever commented on Jan 21, 2024

    @theelderbeever
    Author

    Events on the ingress.
    image

    I tried manually editing the secret however, the secret just reverts when changing the serve-config key.

    I would suspicious of it not being able to get the Service just once though.... I have this ingress on 3 separate deployments and they all have the same behavior and symptoms.

    I will look through the operator code you linked although I am not the best Go reader... I noticed the version is 1.58 on that commit though? Is that chart available? I am on 1.56.1 but can easily upgrade if a newer one has been released.

  8. irbekrm commented on Jan 21, 2024

    @irbekrm
    Contributor

    @theelderbeever sorry I actually didn't spot the issue on your Ingress spec that you pasted in earlier.
    The event is from here.

    You have .host field set on the rule, but not on the spec.tls.hosts. If you have rules[0].host set, you should also set spec.tls.hosts[0] to the same value (we require that because we only support one hostname per Ingress, not individual ones per rules).

    In your case, I think you can either unset rules[0].host or set it to a hostname that does not include dots and makes sense for you (the full DNS name will then be <hostname>.tail5ec3.ts.net)

  9. irbekrm commented on Jan 21, 2024

    @irbekrm
    Contributor

    Do let me know if that makes sense and hopefully fixes the issue

  10. theelderbeever commented on Jan 21, 2024

    @theelderbeever
    Author

    @irbekrm That was indeed the problem. Thanks for all they help!

  11. theelderbeever commented on Jan 21, 2024

    @theelderbeever
    Author

    @irbekrm Quick follow up question. If I wanted to use Cloudflare to set a publicly set name that just resolves to a machine on my tailnet that is using the ingress can I do that?

    I have tried both CNAMES to the tailnet address as well as A records to the tailscale ip address(this works for devices using the regular ts client) but neither work for the ingress.

    Basically, say I wanted to register the domain nginx.example.com and point it to the tailscale ingress ie: default-nginx-ingress-ingress.tail5ec3.ts.net how might I accomplish that?

  12. irbekrm commented on Jan 23, 2024

    @irbekrm
    Contributor

    @theelderbeever just a heads up that I saw your question. I was under impression that CNAME records should work - but saw some inconsistency there myself. I need to reproduce this again- will aim to get back to you in the next few days.

  13. theelderbeever commented on Jan 23, 2024

    @theelderbeever
    Author

    @irbekrm I appreciate it. From what I have turned up so far I think the answer is NO, CNAMES won't work due to the MagicDNS name resolution not being recursive.

    I have tried few things so far if it helps

    • Ingress with tailnet fqdn with public DNS CNAME pointing at it. Does not work and won't resolve nslookup can't even find it.
    • Ingress with machine IP address and public A record. Same as above
    • LoadBalancer SVC: CNAME doesn't resolve, A Record resolves but without TLS (maybe I need to setup something with cert-manager here)
    • A record pointing at non-kubernetes machine ip. Also works but without TLS

    Not sure if the above helps but, its where I have gotten so far.

  14. c-p-b commented on Jan 28, 2024

    @c-p-b

    FWIW regarding configuring DNS to point at a tailscale-enabled nginx-ingress controller Loadbalancer I experimented with similar setups today and this is what I got working

    • Tailscale Split DNS is configured to have queries to a url like internal.example.com point at an internal DNS server Tailscale IP on the tailnet (just a coreDNS helm chart I have running in the cluster, exposed to tailnet with the Service annotation)
    • That internal CoreDNS has a zone/A record that points at an nginx-ingress controller of type: LoadBalancer and loadBalancerClass: tailscale, with some subdomain zone like mysubdomain.ingress.internal.example.com
    • That nginx-ingress controller is configured otherwise in a vanilla setup with an ingressClass called nginx-internal
    • my services do vanilla ingress from there, where I have ingress resources that simply specify their ingress class as nginx-internal.

    Now you are at the point where you are at a vanilla-like setup and you do all the regular things you need to do to get TLS going for that e.g. cert-manager etc. if you need TLS all the way to the application.

    I am guessing there's no current way to have the tailscale operator provision your certs for myservice.mysubdomain.ingress.internal.example.com, that's kind of on the end user to go off and provision those themselves with something like cert-manager. But it gets you TLS termination at/before the ingress which is usually acceptable for a lot of use cases anyway if you didn't want to be in the business of managing cert-manager

    Also there's nothing specific about the above that requires internal DNS, you could set up split DNS and point at cloudflare instead of some internal DNS instead if you wanted to (with the understanding that your internal tailnet urls would be publically visible, though that may be acceptable for you).

  15. added a commit that references this issue on Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions