calico: Switching to eBPF results in calico-kube-controller not being able to reach datastore - localhost:6443 - connection refused

Expected Behavior

I believe the expected behaviour is that the calico-kube-controllers (single pod but that’s the name it has) should be able to contact the Kubernetes API Server in the same way that calico-node pods can.

Current Behavior

calico-node and calico-typha pods can connect to the kubernetes API via localhost:6443 successfully, but calico-kube-controllers (the name of a singular pod in this case) gets connection refused for reasons not yet clear.

Possible Solution

I am not sure what the solution is just yet as I have been following the documentation

Steps to Reproduce (for bugs)

Following documentation here: https://docs.tigera.io/calico/3.27/operations/ebpf/enabling-ebpf#configure-calico-to-talk-directly-to-the-api-server And using the Calico provisioned by Rancher when creating the cluster, self-hosted, RKE2, on Ubuntu VMs, no public cloud present at all.

  1. Disable kube-proxy before following the eBPF documentation linked above. On each node in the cluster, use a daemonset to put a file (99-rke2-customisations.yaml) in /etc/rancher/rke2/config.yaml.d/ (documentation here: https://docs.rke2.io/install/configuration#configuration-file ), and in that daemonset remove the file “/var/lib/rancher/rke2/agent/pod-manifests/kube-proxy.yam” if detected so that the kube-proxy pods don’t come back. The customisations file has the declaration of “disable-kube-proxy: “true”” as per RKE2 documentation.
  2. Define the configmap as defined in the “Operator” step for preparing for eBPF Host=localhost, Port=6443. Watch all the calico-node pods reinit with the new API config environment variables, and work successfully.
  3. Then patch “kind: Installation” with “name: default” to add spec.calicoNetwork: “linuxDataplane: BPF”, which then gives us operational eBPF capabilitiesd (and in-turn correct SourceIP values)
  4. Then patch “kind: FelixConfiguration” with “name: default” to add spec values “bpfKubeProxyIptablesCleanupEnabled: true”, “featureDetectOverride: “ChecksumOffloadBroken=false””, “pfExternalServiceMode: “DSR””, & “xdpEnabled: true” (I have tried with and without these Felix customisations, it does not seem to impact the behaviour of calico-kube-controllers

Context

So when I look at the YAML for calico-kube-controllers it is given the same environment variables KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT that the calico-node & calico-typha pods are given. The calico-kube-controllers pod has an IP of 10.42.790.200 (and changes with re-init of course). And I am using all “default” CIDR configurations that RKE2 delivers. So no CIDR customsiations have been made by me. UFW and AppArmor are turned off on the Ubuntu hosts.

When I instead use the VIP of 10.43.0.1 for KUBERNETES_SERVICE_HOST this prevents a rebooted k8s node from fully recovering as nothing can actually talk to the cluster. Namely calico-node pods cannot reach that VIP after a node reboot, so nothing comes up. I was only able to correct this when using “localhost” or “127.0.0.1” (except localhost might be preferable due to contextual agility when used).

Your Environment

  • Rancher to help build/manage the cluster
  • ArgoCD for CD stuff (not inside this cluster but helps manage it)
  • 3x RKE2 nodes, v1.26.15+rke2r1 (all nodes with all roles, this is for testing purposes)
  • Each node on Ubuntu 22.04 provisioned following the RKE2 documentation on requirements
  • MetalLB for Layer 2 ARP IP management and loadbalancer functions (single LAN IP outside the cluster for inbound traffic)
  • k8s team NGINX Ingress
  • Test deployment librespeed to validate SourceIP results (original driving goal around all this)
  • Calico v3.27.2

==== The error that calico-kube-controller spits out is:

[INFO][1] main.go 131: Ensuring Calico datastore is initialized 2024-08-16T16:09:33.924977314Z 2024-08-16 16:09:33.924 [ERROR][1] client.go 295: Error getting cluster information config ClusterInformation="default" error=Get "https://localhost:6443/apis/crd.projectcalico.org/v1/clusterinformations/default": dial tcp [::1]:6443: connect: connection refused 2024-08-16 16:09:33.924 [INFO][1] main.go 138: Failed to initialize datastore error=Get "https://localhost:6443/apis/crd.projectcalico.org/v1/clusterinformations/default": dial tcp [::1]:6443: connect: connection refused 2024-08-16T16:09:38.935878325Z 2024-08-16 16:09:38.934 [ERROR][1] client.go 295: Error getting cluster information config ClusterInformation="default" error=Get "https://localhost:6443/apis/crd.projectcalico.org/v1/clusterinformations/default": dial tcp [::1]:6443: connect: connection refused

==== I am unsure what I should be doing here as I have followed the documentation, and have not found any relevant resources online on what I can do about this. So I really would appreciate help on this matter.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 24 (11 by maintainers)

Most upvoted comments

Would love to have better documentation on this! Especially if kube-vip is a viable option, documenting the steps you took to integrate with that would be awesome.

I already am aspiring to do my best on documenting such things! Once I figure out this last bit I am probably going to do a yuge publication (or multiples?) on my own personal bloggy/articley site to get eCred hehe. But I do suspect that the Calico docs (and Rancher/RKE2 docs?) would probably benefit from such insights too 😄 Yay!

Oh and still feel free to correct me on any inaccuracies/misunderstandings/other details in general. Still lots to learn about k8s ;D

Would love to have better documentation on this! Especially if kube-vip is a viable option, documenting the steps you took to integrate with that would be awesome.

  1. Thanks for clarifying on the network namespace aspect for calico-kube-controllers. I suspected it was something like that, but wasn’t having a good time finding consistent evidence to support/refute that.
  2. I’m using Rancher to provision and manage the RKE2-based clusters, so there’s really no state where I am “prior to launching Calico altogether”. As for specific order-of-operations in provisioning the cluster and such, well I think I have an idea how that might look, but I’m not yet sure, and that’s why I’m taking far too many notes and leveraging Argo+GitLab so I can go forwards/backwards in time to work towards having that fully known (order of operations for provisioning, etc). The “localhost” aspect I wasn’t really considering as intermediary for provisioning, but more for the purpose of experimentation and learning. Trying that value, watching the outcome, poking the things in sensitive spots with pointy things and going “ooo” and “ahhh” then jotting notes down. It never seemed sustainable.
  3. Yeah you are confirming what I suspected in terms of why it is succeeding, and I already anticipated the limitations of using only one control-plane assigned node’s IP. I more did it to see if it would break in ways I didn’t anticipate (and it didn’t). I really do think the kube-vip thing has a substantially high probability of success for solving the matter we’re talking about here, considering that’s what it says on the tin as a solution multiple times (and who doesn’t love tinned food?).
  4. Maybe if I figure this out, it might be prudent for the Calico documentation to include said solution to help $futureHumans? But saying that not trying to put the egg before the horse’s cart.

I don’t think this is the “permanent” way I want this to run, but yeah pretty sure this falls in-line with what’s been presented above. Yikes!

Glad you got something working!

I think the main takeaway here is using KUBERNETES_SERVICE_HOST=<real IP of control-plane node> works because your nodes can reach that address even before Calico is installed, and it works for calico-kube-controllers because it’s a “real” IP in the network and not a resolution that varies based on where it is being checked.

And frankly, this should be fine - the only downside really is that you’re not getting the full benefit of running multiple API servers (i.e., if you need to do a rolling update, there won’t be failover and Calico will just wait for the node you specified to come back online).

You probably don’t need to go through the intermediate steps of using localhost and restarting things, though.

I tried setting KUBERNETES_SERVICE_HOST to “kubernetes.default.svc.cluster.local”

DNS resolution using cluster DNS won’t work until Calico is running - another part of the “catch 22” situation. I think the CNI plugin is using your node’s DNS configuration, which is how it ended up hitting your gateway.

How is it when I use 127.0.0.1/localhost for KUBERNETES_SERVICE_HOST all the pods work (except calico-cube-controllers)? Is it because those working pods init from an external connection context?

calico-node, calico-typha and the CNI plugin all run on the host - localhost resolves to the IP address of the API server running on that node. You should see this if you kubectl get pods -o wide to view those pod’s IP addresses - it should match the apiserver address.

calico-kube-controllers does not run in the host’s network namespace. localhost resolves to its own IP address, which is not the same as the API server address.

And is this from an internal-to-cluster perspective, or external-to-cluster perspective? (as in where I “want” it connecting to).

I’m not entirely sure I understand this question, but Calico wants to connect to an IP address or domain name that can successfully reach the API server without relying on cluster networking being up (i.e., cluster DNS, cluster service implementation, etc), because Calico is responsible for bootstrapping all of those things.

I apologise in advance if I come across as unappreciative or gruff in any way, past, present, or future. I’m both frustrated, and excited to get this sorted.

Not at all 😃

Also… considering my circumstance… should I be enabling eBPF before (or in-parallel with) declaring the KUBERNETES_SERVICE_HOST and _PORT? (And what about disabling kube-proxy? the test above kube-proxy was running at the time)

I would configure the env vars, and disable kube-proxy prior to launching Calico altogether.

To the best of my knowledge, you want something like one of the below options:

  • A DNS record that is resolvable by your hosts and returns the IP address(es) of your control-plane nodes.
  • A reverse proxy with a stable IP that can perform load balancing to one or more control-plane nodes.
  • A network load balancer that can perform the load balancing at the IP layer.

Also, isn’t Calico capable of doing this kube-apiserver loadbalancing internally

The problem here is bootstrapping - Calico needs to be able to talk to the apiserver in order to learn the necessary information in order to do this.

So, Calico can’t just magically detect where the API server is when it doesn’t have access to the API. Something needs to tell Calico where the API server is so that it can set up that load balancing for other pods.

Or if you have a way how to resolve DNS from the hosts, you can use a domain name in KUBERNETES_SERVICE_HOST that maps to multiple IPs for HA. I think Azure does it that way.

To me, the point of the 10.43.0.1 VIP… wasn’t it supposed to be the logical “loadbalanced” IP meeting this function of tolerant of endpoint shenanigans?

It is. However, when using eBPF Calico, Calico becomes responsible for programming that VIP so that it works. So, Calico can’t rely on the VIP that it itself is programming.

Where are you running kubectl from? Are you accessing this cluster by SSHing into the nodes? Typically a cluster will have a public IP address associated with its API that is used for external access (i.e., a cloud LoadBalancer) - this should handle nodes being added/removed, as well as rolling updates, etc.

but calico-kube-controllers (the name of a singular pod in this case)

Just as a side-note, this is because the single pod contains multiple distinct controllers running within it 😄

I think the main issue here is that “localhost” resolves to a different address for different pods. calico/node and calico/typha run in the host network namespace, so localhost for them will resolve to the actual node’s localhost.

However, kube-controllers runs with it’s own network namespace (i.e., hostNetwork false) and so localhost within that pod will resolve to the pod’s local IP, and traffic won’t go to the node itself.

Do you have some sort of proxy running on localhost? Or is this just a single node cluster with the API server running on the node? In the latter case, you probably can just use the real IP of the node hosting the API server instead of using localhost.