Menu Close

Creating a basic Kubernetes cluster with Ansible

This article provides a method to create a simple 3-node kubernetes (k8s) cluster as shown in the image below using ansible. This k8s cluster is built using the latest stable version of kubernetes and the containerd runtime on RHEL 8 nodes.

k8s-simple

Refer my GitHub Repo for an ansible playbook (k8s_create.yaml) that automatically creates the 3-node K8s cluster above.

Pre-Requisites

  • 3 pre-provisioned RHEL 8 nodes with connectivity to the Internet to download packages and images from repositories and registries.
  • A user account (auto.svc in my playbook) with sudo (root) privileges provisioned on the ansible control node and all RHEL 8 nodes. Also ensure that the user’s SSH keys are set up to allow execution of the ansible playbook.
  • The pod network and service network cidr configured in vars/main.yaml. Ensure that you do not use CIDRs that overlap with your external network.

Implementation

STEP 1:  Download the ansible playbook on the ansible control node

git clone https://github.com/cybergavin/kubernetes.git

STEP 2: Configure the required variables

Set the POD and SERVICE network CIDR blocks in vars/main.yaml

STEP 3: Configure the inventory

Add details for the pre-provisioned RHEL 8 nodes to the files/inventory

STEP 4: Execute the playbook

ansible-playbook -i files/inventory k8s_create.yaml

Validation

On the control-plane node, you should see output similar to below when checking the status of the k8s cluster with kubectl:

k8s-cluster-created

NOTE: You may use the above playbook to create kubernetes cluster with more worker nodes. However, the above playbook caters to a control-plane with a single master node.

VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *