From 2cc4fd0be098394425ff483b55915baadb22213e Mon Sep 17 00:00:00 2001 From: Tuan-Dat Tran Date: Mon, 30 Sep 2024 07:51:33 +0200 Subject: [PATCH] Added http lb for lb Signed-off-by: Tuan-Dat Tran --- README.md | 19 +++++++++++++++++++ roles/helm/tasks/main.yml | 3 --- roles/loadbalancer/templates/nginx.conf.j2 | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) delete mode 100644 roles/helm/tasks/main.yml diff --git a/README.md b/README.md index e7cbce4..5569440 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,22 @@ ansible-playbook -i production -J k3s-servers.yml This will run the [./k3s-servers.yml](./k3s-servers.yml) playbook and execute its roles. + +## After successful k3s installation + +To access our Kubernetes cluster from our host machine to work on it via +flux and such we need to manually copy a k3s config from one of our server nodes to our host machine. +Then we need to install `kubectl` on our host machine and optionally `kubectx` if we're already +managing other Kubernetes instances. +Then we replace the localhost address inside of the config with the IP of our load balancer. +Finally we'll need to set the KUBECONFIG variable. + +```sh +mkdir ~/.kube/ +scp k3s-server00:/etc/rancher/k3s/k3s.yaml ~/.kube/config +chown $USER ~/.kube/config +sed -i "s/127.0.0.1/192.168.20.22/" ~/.kube/config +export KUBECONFIG=~/.kube/config +``` + +Install flux and continue in the flux repository. diff --git a/roles/helm/tasks/main.yml b/roles/helm/tasks/main.yml deleted file mode 100644 index 4a19930..0000000 --- a/roles/helm/tasks/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -- include_tasks: installation.yml -- include_tasks: apps.yml diff --git a/roles/loadbalancer/templates/nginx.conf.j2 b/roles/loadbalancer/templates/nginx.conf.j2 index 0e384ac..e2f0197 100644 --- a/roles/loadbalancer/templates/nginx.conf.j2 +++ b/roles/loadbalancer/templates/nginx.conf.j2 @@ -14,3 +14,17 @@ stream { proxy_pass k3s_servers; } } + +http { + upstream k3s_servers { + {% for ip in k3s_server_ips %} + server {{ ip }}; + {% endfor %} + } + + server { + location / { + proxy_pass http://k3s_servers; + } + } +}