calico: Calico Node Pod Failing - cni-installer/ : Unable to create token for CNI kubeconfig error=Unauthorized

Fresh Calico Operator(v3.27.0) Installation in 1.24 EKS cluster.

kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml
NAME                                       READY   STATUS                  RESTARTS        AGE
calico-kube-controllers-6bf98f54bb-bqtmq   1/1     Running                 0               15h
calico-node-47bvv                          0/1     Init:CrashLoopBackOff   167 (75s ago)   13h
calico-node-7wll8                          0/1     Init:CrashLoopBackOff   2 (23s ago)     70s
calico-node-br5qp                          0/1     Init:CrashLoopBackOff   6 (2m26s ago)   8m16s
calico-node-gln78                          0/1     Init:CrashLoopBackOff   8 (5m13s ago)   22m
calico-typha-5d4689887f-s9qkr              1/1     Running                 0               15h
calico-typha-5d4689887f-wdgdg              1/1     Running                 0               15h
csi-node-driver-26z8d                      2/2     Running                 0               15h
csi-node-driver-pzlhk                      2/2     Running                 0               15h
csi-node-driver-r4jtl                      2/2     Running                 0               71s
csi-node-driver-x8qn4                      2/2     Running                 0               15h

Expected Behavior

All Pods should we be running state

Current Behavior

calico-node pod throwing this Error.

2023-12-21 08:32:31.622 [ERROR][1] cni-installer/<nil> <nil>: Unable to create token for CNI kubeconfig error=Unauthorized
2023-12-21 08:32:31.622 [FATAL][1] cni-installer/<nil> <nil>: Unable to create token for CNI kubeconfig error=Unauthorized

Possible Solution

Steps to Reproduce (for bugs)

It’s Fresh installation

2023-12-21 08:32:31.622 [ERROR][1] cni-installer/<nil> <nil>: Unable to create token for CNI kubeconfig error=Unauthorized
2023-12-21 08:32:31.622 [FATAL][1] cni-installer/<nil> <nil>: Unable to create token for CNI kubeconfig error=Unauthorized

Context

Your Environment

  • Calico version - v3.27.0
  • Orchestrator version (e.g. kubernetes, mesos, rkt): EKS 1.24

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 30 (12 by maintainers)

Most upvoted comments

For anyone encountering this issue, please run the following command to determine if your cluster’s RBAC is correct:

kubectl auth can-i create serviceaccounts/calico-cni-plugin -n calico-system --subresource token --as "system:serviceaccount:calico-system:calico-node"

This should return yes, indicating that calico-node is allowed to create tokens for the CNI plugin. If this returns yes, then Calico’s RBAC is configured correctly and the Unauthorized likely means something else - for example, bad certificates being provided to the containers.

If this returns no, that indicates that something is wrong with the RBAC in the cluster.

@oniubi please see this comment: https://github.com/projectcalico/calico/issues/8368#issuecomment-2120873448

If that doesn’t help, then please raise a new issue.

@ajaypraj

{“log”:“2024-06-05 12:38:15.352 [ERROR]. [1] cni-installer/\u003cnil\u003e \u003cnil\u003e: Unable to create token for CNI kubeconfig error=Post "https://172.16.0.1:443/api/v1/namespaces/kube-system/serviceaccounts/calico-cni-plugin/token\”: dial tcp 172.16.0.1:443: i/o timeout\n",“stream”:“stderr”,“time”:“2024-06-05T12:38:15.352838536Z”}

what address is 172.16.0.1:443 attached to? as error dial tcp 172.16.0.1:443: i/o timeout\n" may be the issue and seperate to calico

other command that may assist in fault finding:

  • kubectl get endpoints -A
  • iptables -nvL pay particular attention to the chains prefixed with KUBE- i.e. KUBE-FORWARD
  • curl -k https://<service ip for kubernetes.default >:443/api should return JSON stating unauthorized access. this is good as it shows api connectivity OK.
kubectl auth can-i create serviceaccounts/calico-cni-plugin -n calico-system --subresource token --as "system:serviceaccount:calico-system:calico-node"

This command checks if the CNI plugin has the necessary permissions. If it does not, it means the ClusterRole, ClusterRoleBinding, or ServiceAccount are not correctly configured or installed on the cluster.

For anyone experiencing this, please first verify that the Calico CNI plugin RBAC resources exist on the cluster:

kubectl get clusterrole calico-cni-plugin
kubectl get clusterrolebinding calico-cni-plugin
kubectl get serviceaccount -n calico-system calico-cni-plugin

If any of those do not exist, it means the tigera/operator is struggling to create them for some reason. Please look at the tigera-operator logs, and the output from kubectl describe tigerastatus calico to see what the issue might be.

If those resources do exist, the next thing to check is whether they are stuck in a Terminating state or not. You can do this by checking the deletionTimestamp field on each of them.

kubectl get clusterrole calico-cni-plugin | grep deletionTimestamp
kubectl get clusterrolebinding calico-cni-plugin | grep deletionTimestamp
kubectl get serviceaccount -n calico-system calico-cni-plugin | grep deletionTimestamp

If you see a deletionTimestmp field on any of them, it means that the resource is trying to be deleted but is stuck. In this case, you need to edit each resource to remove the cni-protector entry from the finalizers field to allow the resources to terminate and the tigera-operator to re-create them. Once that is done, you can restart calico/node and things should start to function.

This is a result of a bug that is triggered often when deleting / re-creating the Installation resource, or manually deleting the RBAC resources by hand. The former has been fixed in v3.28, and the latter should be simply be avoided. If you do need to delete these by hand without deleting the Installation, know that you will need to manually remove the finalizer and that they will be recreated by the operator.

@caseydavenport I am running on AWS (but not EKS)