kubeadm token create with Ansible

4/17/2018

I'm running a Kubernetes cluster on bare metal and I'm writing an Ansible task to get the join command from a master node:

- name: Get join command from master
  shell: kubeadm token create --print-join-command
  when: role == "master"
  run_once: true
  register: join_command

When I run the playbook, I got the following error: "unable to create bootstrap token after 5 attempts []".

If I run the exact same command (kubeadm token create --print-join-command) directly on the master host or remotely using ssh kube-master kubeadm token create --print-join-command, it outputs the join command correctly.

I've ran out of options here... any ideas?

-- Stingus
ansible
kubernetes

2 Answers

4/17/2018

There was a proxy configuration set in the ansible playbook:

---

- hosts: [vmsk8s]
  roles:
    - vmsk8s
  environment:
    http_proxy: http://10.0.0.1:3128
    https_proxy: http://10.0.0.1:3128

Removing the proxy environment vars fixed the problem.

-- Stingus
Source: StackOverflow

4/17/2018

You can get that error if your "kubeadm" cannot connect to the Kubernetes cluster using credentials from the configuration file. You can reproduce it by stopping the docker service on your master node.

There is no difference between running the command using Ansible or shell in your case, so it should work.

So, the only things I can suggest are:

  1. Verify that the Ansible role master is attached to the right host.
  2. Check if the Ansible user has access to the kubeadm configuration, its default path is /etc/kubernetes/admin.conf, and make sure that configuration is right. You might try to run the command as root using the become: true option.
-- Anton Kostenko
Source: StackOverflow