Skip to content

slackr/kube-cluster

Repository files navigation

cluster management host dependencies

apt install ansible pdsh

create ansible 'hosts' file from .template

cp hosts.template hosts

create pdhs 'pdsh_hosts' file from .template

cp pdsh_hosts.template pdsh_hosts

if ssh key is password-protected

ssh-agent bash
ssh-add ~/.ssh/id_rsa

init cluster

ansible-playbook -i ./hosts ./init.yml

install deps on all nodes

ansible-playbook -i ./hosts ./deps.yml

setup master

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

verify master is online

ssh k8s@master_ip
kubectl get nodes

join worker nodes to cluster

ansible-playbook -i ./hosts ./nodes.yml

verify nodes are online

ssh k8s@master_ip
kubectl get nodes

reset kube cluster

pdsh -w ^pdsh_hosts -R ssh "kubeadm reset -f"
pdsh -w ^pdsh_hosts -R ssh "rm -rf /etc/cni/net.d"
pdsh -w ^pdsh_hosts -R ssh "ip link delete flannel.1; ip link delete cni0"
pdsh -w ^pdsh_hosts -R ssh "ip link delete cni0"
pdsh -w ^pdsh_hosts -R ssh "rm -rf /home/k8s/.kube"
pdsh -w ^pdsh_hosts -R ssh "rm -rf /root/*.log; rm -rf /home/k8s/*.log"

# wipe docker
pdsh -w ^pdsh_hosts -R ssh "apt-get purge docker-ce docker-ce-cli containerd.io; apt autoremove"
pdsh -w ^pdsh_hosts -R ssh "rm -rf /var/lib/docker"

# wipe k8s
pdsh -w ^pdsh_hosts -R ssh "apt-get apt-get purge kubeadm kubectl kubelet kubernetes-cni kube*; apt autoremove"
pdsh -w ^pdsh_hosts -R ssh "rm -rf /etc/cni /etc/kubernetes /var/lib/dockershim /var/lib/etcd /var/lib/kubelet /var/run/kubernetes ~/.kube/*"
pdsh -w ^pdsh_hosts -R ssh "iptables -F && iptables -X; \
iptables -t nat -F && iptables -t nat -X; \
iptables -t raw -F && iptables -t raw -X; \
iptables -t mangle -F && iptables -t mangle -X"

update keyserver with k8s repo keys if needed

pdsh -w ^pdsh_hosts -R ssh "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys [key from apt update error]"

kubectl alias with completion

alias k=kubectl
complete -F __start_kubectl k

About

deploy k8s cluster with ansible

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published