Setting Up the CKA Cluster with Ansible

This guide provides step-by-step instructions for setting up the CKA cluster using Ansible, including the creation of the control plane (master node) and three worker nodes. The entire setup can be completed in approximately 15 minutes with the C2 Platform.

Projects: c2platform/ansible


Prerequisites

Setup Control Plane

To set up the control node, run the following command. This process takes about 4 minutes to complete:

vagrant up c2d-cka-cp

Wait until the node status changes to “Ready”:

kubectl get nodes -w
Show me
98° [:ansible-dev]└2 master(+175/-122)* ± kubectl get nodes -w
NAME         STATUS     ROLES           AGE   VERSION
c2d-cka-cp   NotReady   control-plane   23s   v1.28.15
c2d-cka-cp   Ready      control-plane   24s   v1.28.15

Setup Worker Nodes

Next, set up the worker nodes. This process will take approximately 11 minutes:

vagrant up c2d-cka-worker{1..3}

Then, monitor their progress as they join the cluster:

kubectl get nodes -w
Show me

Note that the version currently displayed is v1.28.15. You can change the version by modifying the variable c2_cka_k8s_version, which is defined in the inventory project c2platform/ansible in the file group_vars/cka/main.yml.

[ostraaten@io3 ckad-study-guide (|kubernetes-admin@kubernetes:N/A)]$ kubectl get nodes
NAME              STATUS   ROLES           AGE     VERSION
c2d-cka-cp        Ready    control-plane   25m     v1.28.15
c2d-cka-worker1   Ready    worker          11m     v1.28.15
c2d-cka-worker2   Ready    worker          8m14s   v1.28.15
c2d-cka-worker3   Ready    worker          4m34s   v1.28.15

Create and Restore Snapshots

Creating and restoring snapshots is straightforward and especially useful when preparing for the CKA exam. Snapshots enable you to easily reset the cluster to its original state after completing various exercises.

To set up your environment, execute the following commands:

export BOX_SS=v0
export BOX="c2d-cka-cp c2d-cka-worker1 c2d-cka-worker2 c2d-cka-worker3"

To create a snapshot v0 for all boxes:

for i in $BOX; do vagrant snapshot save $i $BOX_SS; done

To restore this snapshot v0:

for i in $BOX; do vagrant snapshot restore $i $BOX_SS; done