Cluster Creation
We're nearly there. We installed all our prerequisites, and now we're ready to create our Kubernetes cluster. We will aim at an environment that mimics a real-world cluster as closely as possible - this implicates a few things:
- we want more than one node - otherwise we won't see many of Kubernetes' strengths in action
- we want proper connectivity from the outside
Let's get started with KinD's config.
KinD
KinD gets configured at the time of cluster creation by passing a configuration file. So, let's start by creating a new working directory for the remainder of this workshop to use.
mkdir k8s-workshop && cd k8s-workshop
vim kind-config.yaml
K8s?
K8s has become a common abbreviation for Kubernetes, as the word is quite long and hard to type. It is pronounced kates and you will see it throughout this workshop.
Similar phenomena include O11y (observability), or A11y (accessibility).
Configuration
We want to create the following configuration - feel free to expand the various tooltips for explanations of the different settings.
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: workshop-cluster
nodes: # (1)!
- role: control-plane
extraPortMappings: # (2)!
- containerPort: 80
hostPort: 80
listenAddress: "127.0.0.1"
protocol: TCP
- containerPort: 443
hostPort: 443
listenAddress: "127.0.0.1"
protocol: TCP
- containerPort: 31000
hostPort: 31000
listenAddress: "127.0.0.1"
protocol: TCP
labels: # (3)!
ingress-ready: "true"
- role: worker
extraPortMappings:
- containerPort: 31000
hostPort: 31001
listenAddress: "127.0.0.1"
protocol: TCP
- role: worker
extraPortMappings:
- containerPort: 31000
hostPort: 31002
listenAddress: "127.0.0.1"
protocol: TCP
- We want three nodes - one control plane member and two workers. This checks the more than one node box.
-
We want to expose ports 80 and 443 on the host machine. KinD can do this by itself, unless we are running on Docker Desktop - so it's better to make sure 😉
We also want to expose port 31000 on all nodes. We will need this extra port for one of the labs later in this workshop.
This checks the proper connectivity box.
-
We want to label our control plane node so that we can deploy an ingress controller on it later on.
Deployment
Once we've written our config file, we can create our cluster. This will take a few minutes if this is your first KinD cluster, so feel free to grab a coffee or a tea in the meantime.
kind create cluster --config kind-config.yaml
Deployment crashed?
Unfortunately, KinD runs into some edge cases due to Docker Desktop, OS networking stacks, and other factors here and there. I tried to keep the installation path as 'broad' as possible, but if your installation fails here, check out the troubleshooting section of the KinD documentation.
Verification
The cluster is installed, we did it! 🥳 Let's check if everything's alright:
kubectl config use-context kind-workshop-cluster
kubectl get nodes
Once entered, the output should look like this:
NAME STATUS ROLES AGE VERSION
workshop-cluster-control-plane Ready control-plane 4m6s v1.27.3
workshop-cluster-worker Ready <none> 3m42s v1.27.3
workshop-cluster-worker2 Ready <none> 3m47s v1.27.3
✅ Our cluster is indeed running and reachable using kubectl
, and all nodes display a status of Ready
.
This is it, as far as setting things up is concerned. From now on, we will learn how to actually interact with a Kubernetes cluster, how to deploy workloads, and how to connect to them!
Created: September 14, 2023