Connecting the dots, and now what?
With enough conceptual introduction, let’s visualize our understanding by building a simple example. In order to do so, there is going to be two part exercise. First, environmental setup for tools such as Helm, Kubernetes, and Terraform is necessary. Once the environmental setup is done, there comes the fun coding part. First this post covers Kubernetes creation of pods and clusters with kind and monitoring with Docker Desktop.
Create a designated folder
In order to organize this exercise as much as possible, let’s start from creating a folder called First-Terraform in your desktop. This folder will contain files we create for the walk throughs. Open up your terminal and go to the folder you just created.
Before we fully begin
This posts assume that you have following already installed locally on your computer: Terraform, Helm, and Kind.
If not, resources below guides you through an installation of resources we need.
- Docker Desktop installation – https://www.docker.com/products/docker-desktop/
- Kubectl installation – https://kubernetes.io/docs/tasks/tools/
- Kind installation – https://kind.sigs.k8s.io/docs/user/quick-start/#installation
- Helm installation (using package manager is recommended for easy installation) – https://helm.sh/docs/intro/install/
- Terraform CLI installation – https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli
Starting locally with Kind
Kind is a tool for running Kubernetes clusters locally. However, Docker Desktop needs to be running in the background. According to the documentation, “kind runs Kubernetes clusters by using Docker containers as ‘nodes’” So the Docker first needs to be running in order to create a kind cluster.
Once the Docker desktop is running, the command to create kind cluster is:
kind create cluster
this command create a single kind cluster with default name, ‘kind’
Creating a tutorial cluster with following command:
kind create cluster --name="tutorial-1"
--name
argument enables creation of cluster with specified name. In order to check if the node has been correctly created, we can run:
kubectl get nodes
This command shows a list of existing nodes that is running locally.
Creating kind cluster with .yaml config file
Specifying every details about the cluster created on command line is a daunting and error prone task. YAML configure file with declarative syntax allows us to create a cluster with desired characteristics.
- Create a .yaml file with
touch config.yaml
. YAML is a human readable data serialization language used for writing configuration file (Red hat). - Open
config.yaml
, withnano config.yaml
. - Write the configuration as follows to create a cluster named tutorial-1 with one control plane nodes, and two worker nodes.
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: tutorial-1
nodes:
- role: control-plane
- role: worker
- role: worker
Other than designating roles to nodes, you can specify internet protocol versions, ports to be exposed and more.
Two worker nodes hosts pods to run containerized applications while a control-plane manages the worker nodes and monitor the cluster.
What is next?
Now we have warmed up to creating kind cluster, we would like to go into Terraform and creating cluster, manage them, and observe how we can use helm, Kubernetes and terraform altogether.
Reference
- YAML file: https://www.redhat.com/en/topics/automation/what-is-yaml.
- More example and practice with kind: https://kind.sigs.k8s.io/docs/user/quick-start/#creating-a-cluster
- More on worker and control plane: https://kubernetes.io/docs/concepts/overview/components/#:~:text=The%20control%20plane%20manages%20the,fault%2Dtolerance%20and%20high%20availability.