diff --git a/Makefile b/Makefile index 473fbf17fa77897d64616b3bd3ec67fc5fa48de8..c57479cc199ef7abbdabfa8ea33e4c8284e5715f 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,9 @@ cli-config: ## Configure koolbox CLI (To setup terraform values as well was toke .PHONY: deploy deploy: check-machine ## Deploy infrastructure on Hetzner Cloud cd ./terraform && make apply + date + sleep 600 + make kubernetes-install .PHONY: destroy destroy: check-machine ## Destroy infrastructure on Hetzner Cloud diff --git a/utils/flux.mk b/utils/flux.mk new file mode 100644 index 0000000000000000000000000000000000000000..a2b8f69e130717515de9d4aa95d90d02dc9211ed --- /dev/null +++ b/utils/flux.mk @@ -0,0 +1,22 @@ +.PHONY: flux-preflight +flux-preflight: + # Checking for required variables + env | grep -Pe '^GITLAB_TOKEN' > /dev/null + +.PHONY: flux-watch +flux-watch: ## flux: Show currently deployed resources an their status in all namespaces + koolbox flux get all --all-namespaces + +.PHONY: flux-update-git +flux-update-git: ## flux: Reload flux-system repository + koolbox flux reconcile source git flux-system + +.PHONY: flux-bootstrap +flux-bootstrap: flux-preflight + flux bootstrap gitlab \ + --hostname=git.shivering-isles.com \ + --ssh-hostname=git.shivering-isles.com:2222 \ + --ssh-key-algorithm ed25519 \ + --owner=shivering-isles \ + --repository=infrastructure-gitops \ + --path=clusters/k8s01 diff --git a/utils/kubernetes-init.mk b/utils/kubernetes-init.mk new file mode 100644 index 0000000000000000000000000000000000000000..c43edcf21d31657fcf96dfda90e104f664bb3119 --- /dev/null +++ b/utils/kubernetes-init.mk @@ -0,0 +1,24 @@ +.PHONY: kubeadm-init +kubeadm-init: + ssh node01.$(TF_VAR_dns_domain) kubeadm init --control-plane-endpoint "api.$(TF_VAR_dns_domain):6443" --upload-certs --pod-network-cidr "192.168.0.0/16" + ssh node01.$(TF_VAR_dns_domain) systemctl enable kubelet.service + +kubeadm-copy-config: ## Copy Kubernetes admin config from node01 to the local machine + scp node01.$(TF_VAR_dns_domain):/etc/kubernetes/admin.conf /root/.kube/config + +kubeadm-join-masters: + ssh node02.$(TF_VAR_dns_domain) $$(ssh node01.$(TF_VAR_dns_domain) kubeadm token create --ttl 1h --print-join-command --certificate-key "$$(ssh node01.$(TF_VAR_dns_domain) kubeadm init phase upload-certs --upload-certs | tail -1)" | tail -1) + ssh node02.$(TF_VAR_dns_domain) systemctl enable kubelet.service + ssh node03.$(TF_VAR_dns_domain) $$(ssh node01.$(TF_VAR_dns_domain) kubeadm token create --ttl 1h --print-join-command --certificate-key "$$(ssh node01.$(TF_VAR_dns_domain) kubeadm init phase upload-certs --upload-certs | tail -1)" | tail -1) + ssh node03.$(TF_VAR_dns_domain) systemctl enable kubelet.service + +kubectl-remove-first-master-taints: + kubectl taint nodes node01.$(TF_VAR_dns_domain) node-role.kubernetes.io/master- + +kubectl-remove-all-master-taints: + kubectl taint nodes --all node-role.kubernetes.io/master- || true + +kubectl-delete-wrong-subnet: + kubectl get pods --all-namespaces -o wide | grep 10.85. | awk '{print "-n " $$1 " " $$2}' | xargs -L 1 kubectl delete pod + +kubernetes-install: kubeadm-init kubeadm-copy-config kubectl-remove-first-master-taints flux-bootstrap kubeadm-join-masters kubectl-remove-all-master-taints kubectl-delete-wrong-subnet