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.
- 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.
- 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.
- 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)
- 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)
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.
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
localhostand restarting things, though.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.
calico-node,calico-typhaand the CNI plugin all run on the host -localhostresolves to the IP address of the API server running on that node. You should see this if youkubectl get pods -o wideto view those pod’s IP addresses - it should match the apiserver address.calico-kube-controllersdoes not run in the host’s network namespace.localhostresolves to its own IP address, which is not the same as the API server address.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.
Not at all 😃
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:
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_HOSTthat maps to multiple IPs for HA. I think Azure does it that way.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.
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/nodeandcalico/typharun in the host network namespace, solocalhostfor them will resolve to the actual node’s localhost.However, kube-controllers runs with it’s own network namespace (i.e.,
hostNetwork false) and solocalhostwithin 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.