Blog by Yan

Install Kubernetes with Kubespray and ansible

April 09, 2019


  • 3 Computers with Ubuntu OS
  • One for Operation of Ansible execution -
  • One for K8s Master Host -
  • One for K8s Node Host -

Preparation (On Operation Computer)

Preparation of Hosts for passwordless sudoers

  • Login to K8s Master Host with ssh
  • ssh masterhostuser@
  • Set root passsword if you haven’t yet sudo passwd root
  • sudo vim /etc/ssh/sshd_config
  • Set PermitRootLogin=yes
  • Restart ssh sudo systemctl restart ssh
  • Logout with logout
  • Do the same for K8s Node Host
  • Make root passwords the same

Preparation for Ansible Environemnt

  • Create private key for ansible execution on hosts
  • ssh-keygen -t rsa -b 4096 -C "" &% default values are fine.
  • Copy the key to hosts
  • ssh-copy-id root@
  • ssh-copy-id root@
  • Check if you can login without password to both hosts with ssh root@ & ssh root@

Preparation of Ansible Configuration

  • Clone the Ansible Config for Kubespray
  • git clone
  • cd kubespray
  • Install python-pip sudo apt install python-pip python3
  • Install dependencies from requirements.txt
  • cp -rfp inventory/sample inventory/mycluster
  • declare -a IPS=(
  • CONFIG_FILE=inventory/mycluster/hosts.ini sudo python3 contrib/inventory_builder/ ${IPS[@]}
  • Copy the file to inventory folder
  • cp inventory/sample/hosts.yaml inventory/mycluster/hosts.yaml
  • Change as the following config
node1  ansible_host= ip=
node2  ansible_host= ip=







RUN Ansible Cookbook

  • Run Ansible with this command
  • ansible-playbook -i inventory/mycluster/hosts.yaml --become --become-user=root cluster.yml -K

Yan Lin Aung

Written by Yan Lin Aung who lives and works in Yangon building useful things. You should follow him on Twitter