Getting kubeconfig via role
Role have ability to download kubeconfig file to machine from where ansible was run. To use it, set following variables:
Role will perform following:-
Copy
/etc/rancher/k3s/k3s.yml
to~/.kube/config-${ k3s_kubeconfig_context
} -
Patch it with your preferred context name specified in
k3s_kubeconfig_context
variable instead of stockdefault
-
Patch it with proper server URL (by default, it will be ansible_host of first master node in group specified in variable
k3s_master_group
, with port 6443, aka "initial master"), but you can override it withk3s_kubeconfig_server
-
Download resulting file to machine running ansible with path
~/.kube/config-${ k3s_kubeconfig_context }
, in current example it will be~/.kube/config-k3s-de1
And you can start using it right away.
However, if your master is configured differently (HA IP, Load balancer, etc), you might want to specify server manually. For this, you can use k3s_kubeconfig_server
variable:
/etc/rancher/k3s/k3s.yml
- if you redeploy your k3s cluster and need new kubeconfig, just delete existing local kubeconfig to get new one.