Skip to content

Setup a high availability kubernetes cluster with Ansible

Notifications You must be signed in to change notification settings

dyrnq/kubernetes-ansible

Repository files navigation

kubernetes-ansible

This repository is for installing kubernetes HA cluster by binary step by step using ansible. Support docker(ctr-dockerd)、containerd、cri-o.

install kubernetes by ansible

prepare

  • install virtualbox ref
  • install vagrant ref
  • install ansible ref
vagrant up etcd-1 etcd-2 etcd-3 master-1 master-2 master-3 worker-1 worker-2 worker-3
## need set https_proxy in group_vars/all.yml
ansible-playbook -i inventory/hosts  playbook-grab.yml

## only run once
ansible-playbook -i inventory/hosts  playbook-certs.yml

## only run once
ansible-playbook -i inventory/hosts  playbook-kube-encryption.yml

## only download kubernetes v1.24.4
ansible-playbook -i inventory/hosts -e "kubernetes_ver=v1.24.4"  playbook-grab.yml --tags=path,kubernetes
## only download docker 20.10.17
ansible-playbook -i inventory/hosts -e 'docker_ver=20.10.17'  playbook-grab.yml --tags=path,docker

install etcd

ansible-playbook -i inventory/hosts  playbook-etcd.yml

kube-master

ansible-playbook -i inventory/hosts  playbook-kube-master.yml

kube-worker

ansible-playbook -i inventory/hosts  playbook-kube-worker.yml
## Specify kubernetes version number and cri implementation on worker-2
ansible-playbook -i inventory/hosts -e "run=worker-2" -e "cri=cri-o" -e "kubernetes_ver=v1.24.4" playbook-kube-worker.yml

kube-addons

ansible-playbook -i inventory/hosts  playbook-kube-addons.yml

ansible-role-nginx

If kubernetes.lb.mode value is "nginx", need clone ansible-role-nginx first by script below.

mkdir -p ~/.ansible/roles/
cd ~/.ansible/roles/
git clone --depth=1 git@github.com:nginxinc/ansible-role-nginx.git

ansible execute role from command line

ansible -i inventory/hosts master-1 -m include_role -a name=helm

ref