Skip to content

Installation#

Requirements#

  • git
  • ansible
  • kubectl
  • helm

Preparation#

  • Clone this repository
git clone https://github.com/madic-creates/k3s-git-ops
  • Configure pre-commit-hooks
  • Adapt ansible vars to your needs. For this, copy the "group_vars/all/main.yml" to e.g. ""group_vars/all/own.yml" to override the default vars
cd ansible
cp group_vars/all/main.yml group_vars/all/own.yml

A short explanation of the vars can be found in the vars file. Because they tend to change, I wont document them here.

Ansible inventory#

This playbook requires the following host groups:

  • k3s_server
  • k3s_agent

Example:

1
2
3
4
5
6
[k3s_server]
k3svm1

[k3s_agent]
k3svm2
k3svm3

Installation#

Run ansible from within the ansible folder

cd ansible
ansible-playbook install.yaml -i inventory --diff

Ansible downloads the kubeconfig file to the folder ./shared/${HOSTNAME}/k3s.yaml file. You can use this file to access the cluster.

To get the validity of the kubeconfig file, you can use the following command (either replace $KUBECONFIG with the path to the kubeconfig file or set it as environment variable):

1
2
3
4
5
6
awk '/client-certificate-data:/ {print $2}' $KUBECONFIG | base64 -d | \
openssl x509 -noout -startdate -enddate && \
echo "Valid for: $(awk '/client-certificate-data:/ {print $2}' $KUBECONFIG | \
base64 -d | openssl x509 -noout -enddate | cut -d= -f2 | \
xargs -I{} date -d "{}" +"%s" | \
awk -v now=$(date +%s) '{printf "%.0f\n", ($1-now)/86400}') days"

Kubeconfig validity

Removal#

cd ansible
ansible-playbook remove.yaml -i inventory -l node01.example.com -K --diff

ArgoCD#

kubectl kustomize apps/argo-cd --enable-helm | kubectl apply -f -
kubectl kustomize apps/overlays/vagrant | kubectl apply -f -

Get the ArgoCD Login password for the admin user:

kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d

Remove ArgoCD

kubectl kustomize bootstrap --enable-helm | kubectl delete -f -