🌐
GitHub
github.com › kairen › kubeadm-ansible
GitHub - kairen/kubeadm-ansible: Build a Kubernetes cluster using kubeadm via Ansible.
Build a Kubernetes cluster using kubeadm via Ansible. - kairen/kubeadm-ansible
Starred by 741 users
Forked by 381 users
Languages   Jinja 99.4% | Shell 0.6% | Jinja 99.4% | Shell 0.6%
🌐
Medium
medium.com › @fenari.kostem › effortless-kubernetes-deployment-setting-up-a-cluster-with-ansible-and-kubeadm-cc40f9e716f4
Effortless Kubernetes Deployment: Setting Up a Cluster with Ansible and kubeadm | by Bora Köstem | Medium
November 8, 2024 - We’ll save this configuration file as kubeadm-conf.j2, a Jinja2 template, to take advantage of Ansible’s variable substitution capabilities. The kubeadm configuration file provided here defines key settings for initializing and configuring a Kubernetes cluster.
🌐
GitHub
github.com › geerlingguy › ansible-role-kubernetes
GitHub - geerlingguy/ansible-role-kubernetes: Ansible Role - Kubernetes · GitHub
An Ansible Role that installs Kubernetes on Linux. Requires a compatible Container Runtime; recommended role for CRI installation: geerlingguy.containerd. Available variables are listed below, along with default values (see defaults/main.yml): ...
Starred by 621 users
Forked by 284 users
Languages   Jinja
🌐
GitHub
github.com › npflan › k8s-ansible
GitHub - npflan/k8s-ansible: Ansible for deploying Kubernetes with KubeAdm · GitHub
Quick and dirty ansible for deploying kubernetes with kubeadm.
Starred by 8 users
Forked by 3 users
🌐
Kubernetes
kubernetes.io › blog › 2019 › 03 › 15 › kubernetes-setup-using-ansible-and-vagrant
Kubernetes Setup Using Ansible and Vagrant | Kubernetes
January 3, 2026 - Ansible is an infrastructure automation engine that automates software configuration management. It is agentless and allows us to use SSH keys for connecting to remote machines.
🌐
Spacelift
spacelift.io › blog › ansible-kubernetes
How to Manage Kubernetes with Ansible [Tutorial]
October 10, 2025 - Run the following to create kube_master.yml playbook under ~/ansible/playbooks/. Please make sure to replace YOUR_USERPROFILE_NAME with the name of your user profile that is in your /home/ directory that you are installing Kubernetes under. (For example, I am using ‘kube_admin’). - hosts: master become: yes tasks: - name: Create an Empty file for Kubeadm configuring copy: content: "" dest: /etc/kubernetes/kubeadm-config.yaml force: no - name: Configure container runtime blockinfile: path: /etc/kubernetes/kubeadm-config.yaml block: | kind: ClusterConfiguration apiVersion: kubeadm.k8s.io/v1b
Find elsewhere
🌐
GitHub
github.com › ReSearchITEng › kubeadm-playbook
GitHub - ReSearchITEng/kubeadm-playbook: Fully fledged (HA) Kubernetes Cluster using official kubeadm, ansible and helm. Tested on RHEL/CentOS/Ubuntu with support of http_proxy, dashboard installed, ingress controller, heapster - using official helm charts
modular, clean code, supporting multiple activies by using ansible tags (e.g. add/reset a subgroup of nodes). optionally help configuring container engine (e.g. docker) This project targets to get a fully working environment in matter of minutes on any hw: baremetal, vms (vsphere, virtualbox), etc. k8s version upgrades: while many of its roles can be used for an upgrade, upgrade should be done using kubeadm tool.
Starred by 594 users
Forked by 104 users
Languages   Shell 56.8% | Jinja 43.2% | Shell 56.8% | Jinja 43.2%
🌐
Jnidzwetzki
jnidzwetzki.github.io › 2022 › 02 › 02 › install-kubernetes.html
Install Kubernetes using Ansible / Kubeadm | Jan’s website and blog
February 2, 2022 - $ ansible-playbook playbooks/kubernetes-containerd.yml -i hosts · Now it is time to install the control-plane node. This is done by executing the kubeadm init command. The command performs a few preflight checks (e.g., testing that the distribution is supported by Kubernetes and that a container runtime is installed properly).
🌐
Checkmateq
checkmateq.com › home › ansible script to create kubernetes cluster
Ansible Script to create Kubernetes Cluster
October 19, 2024 - - hosts: master become: yes tasks: - name: initialize the cluster shell: sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --cri-socket=/var/run/crio/crio.sock --ignore-preflight-errors Swap >> cluster_initialized.txt args: chdir: $HOME creates: cluster_initialized.txt - name: create .kube directory become: yes become_user: k8sadmin file: path: /home/k8sadmin/.kube state: directory mode: 0755 - name: copy admin.conf copy: remote_src: yes src: /etc/kubernetes/admin.conf dest: /home/k8sadmin/.kube/config owner: k8sadmin - name: Install calico Pod network become: yes become_user: k8sadmin shell
Top answer
1 of 2
8

There are three ways:

  1. wait_for some time after executing kubeadm init ansible task.
- hosts: master
  become: yes
  tasks:
    - name: initialize the cluster
      shell: kubeadm init --pod-network-cidr=10.244.0.0/16 
    - name: sleep for 20 seconds
      wait_for:
        timeout: 20
  1. Make use of until in ansible.
- hosts: master
  become: yes
  tasks:
    - name: initialize the cluster
      shell: kubeadm init --pod-network-cidr=10.244.0.0/16
      register: result
      until: result.stdout.find("Your Kubernetes master has initialized successfully!") != -1
      retries: 1
      delay: 20

NOTE: Here we retry kubeadm init until we get the string Your Kubernetes master has initialized successfully! in the output.

  1. Check if the file /etc/kubernetes/admin.conf exists after executing kubeadm init ansible task.
- hosts: master
  become: yes
  tasks:
    - name: initialize the cluster
      shell: kubeadm init --pod-network-cidr=10.244.0.0/16
    - name: create .kube directory
      become: yes
      become_user: ubuntu
      file:
        path: $HOME/.kube
        state: directory
        mode: 0755
    - name: Check admin.conf file exists.
      stat:
        path: /etc/kubernetes/admin.conf
      register: k8s_conf
    - name: copy admin.conf to user's kube config
      copy:
        src: /etc/kubernetes/admin.conf
        dest: /home/ubuntu/.kube/config
        remote_src: yes
        owner: ubuntu
      when: k8s_conf.stat.exists

NOTE: Here we execute admin.conf copy only when the k8s config file /etc/kubernetes/admin.conf exists.

2 of 2
1

When I use command module instead of shell module it appears to wait as it has no trouble making the copy of admin.conf. Also my next step after creating the .kube/config is to apply flannel overlay and that also works. Here's what my tasks looks like.

  - name: Initialize the Kubernetes cluster using kubeadm
    command: kubeadm init --config /etc/kubernetes/kubeadminit.yaml

  - name: create .kube in root home
    file:
      path: /root/.kube
      state: directory

  - name: copy kubernetes admin.conf to root home dir
    copy:
      src: /etc/kubernetes/admin.conf
      dest: /root/.kube/config
      remote_src: yes
🌐
Lorenzo Garuti
garutilorenzo.github.io › ansible-role-kubernetes-cluster
Install and configure a high available Kubernetes cluster with Ansible
August 17, 2022 - This ansible role will install and configure a high available Kubernetes cluster. This repo automate the installation process of Kubernetes using kubeadm. This is only a example on how to use Ansible automation to install and configure a Kubernetes ...
🌐
Ansible Galaxy
galaxy.ansible.com › rolehippie › kubeadm
rolehippie.kubeadm
We cannot provide a description for this page right now
🌐
GitHub
github.com › choerodon › kubeadm-ansible
GitHub - choerodon/kubeadm-ansible: Kuberadmin ansible is a toolkit for simple and quick installing k8s cluster.
January 19, 2021 - Kubeadmin ansible is a toolkit for simple and quick installing k8s cluster.
Starred by 39 users
Forked by 34 users
Languages   HTML 88.2% | Shell 11.8% | HTML 88.2% | Shell 11.8%
🌐
GitHub
github.com › enix › ansible-kubeadm
GitHub - enix/ansible-kubeadm: Aims to manage kubeadm based cluster via ansible
Aims to manage kubeadm based cluster via ansible. Contribute to enix/ansible-kubeadm development by creating an account on GitHub.
Starred by 16 users
Forked by 6 users
Languages   Python 56.1% | HCL 14.6% | Jinja 13.3% | Gherkin 10.1% | Shell 2.8% | Dockerfile 1.8% | Smarty 1.3% | Python 56.1% | HCL 14.6% | Jinja 13.3% | Gherkin 10.1% | Shell 2.8% | Dockerfile 1.8% | Smarty 1.3%
🌐
Medium
medium.com › @a.j.longchamps › home-lab-kubernetes-part-3-initializing-the-kubernetes-cluster-with-ansible-d979dc1aeea0
Home Lab Kubernetes Part 3: Initializing The Kubernetes Cluster With Ansible | by Aaron Longchamps | Medium
June 19, 2024 - Anytime you’re running the module ansible.builtin.set_fact with a target set of hosts, Ansible will make that variable available to the target hosts that are in scope. This also means that each host gets its own instance of the variable under its own hostvars. In this playbook, I ask the Kubernetes cluster for the join command and certificate key, then I make it available to all the other hosts by running a play with scope hosts: all. The variable certificate_key_output looks like this: packer@k-control-plane-1:~$ sudo kubeadm init phase upload-certs --upload-certs [upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace [upload-certs] Using certificate key: 8146ef5254a7182c582dd9559fd60fbfea4e03a1b7fdb64720c6476a2755826a packer@k-control-plane-1:~$
🌐
LinkedIn
linkedin.com › pulse › how-kubernetes-yourself-kubeadm-ansible-vagrant-michele-sciabarrà
How to install Kubernetes by yourself - with Kubeadm, Ansible and Vagrant
February 8, 2021 - So to join the cluster you need to provide some secret informations. This secret is a token, that is generated when you perform a kubeadm init on the master. So to automate the node creation with ansible, we collect the output of the master after init, and distribute the command to the nodes where we execute it.
🌐
Fabian Lee
fabianlee.org › 2022 › 05 › 25 › kvm-kubeadm-cluster-on-kvm-using-ansible
KVM: kubeadm cluster on KVM using Ansible | Fabian Lee : Software Engineer
September 12, 2023 - In this article, I will show you how to deploy a three-node Kubeadm cluster on Ubuntu 22 nodes that are created using Terraform and a local KVM libvirt provider. Ansible is used for installation of the cluster.