Search code examples
kubernetesk0s

Why can't I connect via ssh to k0s?


good afternoon, I encountered an error when trying to start the k0s cluster.

FATA apply failed - log file saved to /root/.cache/k0sctl/k0sctl.log: failed on 2 hosts:
 - [ssh] 192.168.0.241:22: retry limit exceeded after 10 attempts: lock file disappeared: failed to stat /tmp/k0sctl.lock: command failed: client exec: command failed: build command: sudo error: sudo required: user is not root and passwordless access elevation (sudo, doas) has not been configured
 - [ssh] 192.168.0.187:22: retry limit exceeded after 10 attempts: lock file disappeared: failed to stat /tmp/k0sctl.lock: command failed: client exec: command failed: build command: sudo error: sudo required: user is not root and passwordless access elevation (sudo, doas) has not been configured

yaml file

apiVersion: k0sctl.k0sproject.io/v1beta1
kind: Cluster
metadata:
  name: k0s-cluster
spec:
  hosts:
  - ssh:
      address: 192.168.0.241
      user: k0snode2
      port: 22
      keyPath: ~/.ssh/id_ed25519
    role: controller
  - ssh:
      address: 192.168.0.187
      user: k0snode
      port: 22
      keyPath: ~/.ssh/id_ed25519
    role: worker

as I understand it, this is due to a malfunction of the ssh key, but when trying to connect via the terminal, everything works

root@serv:/home/user # ssh -i ~/.ssh/id_ed25519 k0snode@192.168.0.187
Welcome to Ubuntu 24.04 LTS (GNU/Linux 6.8.0-38-generic x86_64)

 * Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
 * Support: https://ubuntu.com/pro

 System information as of July 26, 2024, 11:54:00 UTC

  Loading the system: 0.0 Number of processes: 139
  Usage /: 50.6% of the 11.21GB users logged in: 1
  Memory usage: 21% IPv4 address for enp0s3:
192.168.0.187 Swap usage: 0%

 * Strictly limited access to Kubernetes ensures the security of edge and the Internet of Things. Find out how MicroK8s
   I have just raised the bar for a simple, flexible and secure K8s cluster deployment.

   https://ubuntu.com/engage/secure-kubernetes-at-the-edge

Extended Security Maintenance (ESM) for applications is possible.

41 The update can be applied immediately.
What to see in addition: a list of suitable options - with the possibility of updating

Include the following applications for more information about general security.
To see https://ubuntu.com/esm or add: sudo pro status


*** A system reboot is required ***
A kernel update is expected!
Running kernel version:
6.8.0-38-generic
Diagnostics:
  The current kernel version does not match the expected kernel version 6.8.0-39-generic.
Last login: Fri, July 26, 11:42:19 2024 from 192.168.0.191
k0snode@k0snode:~$

I also tried to change the permission to authorized_keys with the chmod 0600 authorized_keys command, but it didn't help


Solution

  • The error is not that SSH does not work, but that the remote user does not have a passwordless sudo or doas setup. This is a requirement for k0sctl to work. Setting up passwordless sudo is e.g. described here.