Lab 2: Automate the K3s clusters deployment with Ansible
Starting a local Kubernetes cluster in our home lab environment may become complicated if we use kubeadm or any other distributions.
I seek to establish a Kubernetes cluster that operates seamlessly within an Ansible-driven ecosystem, allowing for scripted control over the cluster's nodes. This setup enables the automation of both the construction and decommissioning of nodes within the cluster, providing the flexibility to manage its lifecycle as required.
Therefore, I chose k3s-ansible
to build my on-premise Kubernetes cluster.
Continue later...
Post-Deployment
After the deployment, you may need to get a copy of kube config file from each of the master nodes.
Run the following commands
$ scp k3s-master-node01:~/.kube/config ~/.kube/k3s-master-node01
Please replace k3s-master-node01 with the hostname or IP addresses of your master node. You may need to repeat the command if you have more than one master node.
Please also replace the following parameters in each of the kube config file, so that when you run $ kubectl config get-context
you will see the name of the nodes correctly.
Example config file:
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJkakNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pP
server: https://192.168.2.1:6443
name: k3s-master-node01 //change here
contexts:
- context:
cluster: k3s-master-node01 //change here
user: default //remain here. we are gonna use default user
name: k3s-master-node01 //change here
current-context: k3s-master-node01 //change here
kind: Config
preferences: {}
users:
- name: default //remain here
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJrakNDQVRlZ0F3SUJBZ0lJTFBqR0ZBcndTUlF3
Then, test the connectivity with the following command
$ kubectl get nodes
My results:

Last updated