I am using Ansible to automate the setup of a Kubernetes cluster. The master node setup works fine, but I’m having issues when trying to join worker nodes to the cluster. This is the only part where SSH fails. I can connect manually, and I have installed all dependencies using my playbook, but joining the cluster fails every time.
The relevant task in my role is as follows:
- name: Join cluster
ansible.builtin.shell: "{{ join_command }} >> node_joined.log"
args:
chdir: /home/ubuntu
creates: node_joined.log
vars:
ansible_command_timeout: 3000
when: join_command is defined
join_command comes from this task:
- name: Set join command
ansible.builtin.set_fact:
join_command: "kubeadm join --token {{ join_token }} {{ master_node_ip }}:6443 --discovery-token-ca-cert-hash sha256:{{ ca_cert_hash.stdout }}"
run_once: true
I keep encountering the following error message during the execution of the task:
TASK [kubernetes-worker-setup : Join cluster] **********************************
task path: /home/runner/work/kubernetes/kubernetes/roles/kubernetes-worker-setup/tasks/main.yml:39
Read vars_file 'vars.yml'
fatal: [k8s-master-3]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: OpenSSH_8.9p1 Ubuntu-3ubuntu0.10, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 195.201.11.184 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/runner/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/runner/.ssh/known_hosts2'
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 1846
debug3: mux_client_request_session: session request sent
debug1: mux_client_request_session: master session id: 2
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Control master terminated unexpectedly
Shared connection to 195.201.11.184 closed.",
"unreachable": true
}