5 Fastest Ways to Build Your First Kubernetes Cluster
Tags: kubernetes, cloud, tutorial
Published: 2022-09-07 02:19:12

Kubernetes is our present. However, it still scares away by its complexity. Where do I even start? How to install Kubernetes? What is minikube? Which type of Kubernetes cluster should I choose? 

If any of these questions relate to you, you’ve come to the right place. Stay tuned and follow along for the best options for creating your first cluster in this Kubernetes tutorial.

#Option 1 – Kubernetes playground
Kubernetes playground is the easiest way to install a Kubernetes cluster. In fact, you are not even installing anything. Instead, you run your Kubernetes cluster directly in a browser tab.

##Pros
**Easy to start.** No complex configuration is required. The Kubernetes cluster is available with a click of a button.

**Runs in a browser.** Does not consume the resources of your laptop and can be launched from any location and any operating system.

**Free.** You can use it without any obligations. You don’t even have to provide your email! That’s as simple as that –  a free Kubernetes cluster for you to play with.

##Cons
**Limited functionality.** Obviously, that’s just a sandbox which is acceptable only when you are getting started with Kubernetes You can’t customize the environment, scale the cluster, or deploy any meaningful workload to this platform.

**Deployments are not persisted.** Every time you close or restart your browser, the progress will be lost.

##Steps to deploy
Just open https://training.play-with-kubernetes.com/kubernetes-workshop/

#Option 2 – Install Kubernetes using Minikube
Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virtual Machine on your laptop.

##Pros
**Easy to start.** Even though it requires extra configuration, it is still relatively easy to install minikube.

**Free.** Minikube is an open-source tool. That means you can download, use, and even modify it as you see fit without restrictions or limitations.

##Cons
**Limited functionality.** It’s much better than a browser-based Kubernetes platform. However, there are still features that are not supported or do not work well in minikube.

**Consumes resources.** It runs on your laptop and in some cases requires a fair amount of resources, such as CPU and memory.

**Not a production-ready solution.** Minikube is a perfect option for local development. However, you can’t send your laptop to your client. For production-level use cases, you’ll need something else.

##Steps to deploy
###Here is how to install minikube on ubuntu (or any similar Linux system):
```
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minkube start
```

###Here is how to install minikube on mac:
```
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64
sudo install minikube-darwin-amd64 /usr/local/bin/minikube
minikube start
```

###Here is how to install minikube on windows:
- Install Windows Package Manager: https://docs.microsoft.com/en-us/windows/package-manager/
- Run the commands:
```
winget install minikube
minikube start
```
The best way to check if Kubernetes is installed is to attempt to connect to your cluster and run some kubectl commands:
```
kubectl get nodes
```
#Option 3 – Install Kubernetes using Kubeadm
Kubeadm is a tool designed to bootstrap a full-scale Kubernetes cluster. It takes care of all heavy lifting related to cluster provisioning and automates the process completely.

##Pros
**Supports all features of Kubernetes.** Clusters created with kubeadm are fully functional and conform with all the best practices of Kubernetes.

**Production-grade solution.** It is absolutely safe to use kubeadm-created clusters not just in sandboxes and pet projects, but in real-world, production use cases as well.

##Cons
**Require additional resources.** Even though you can create a single-node cluster on your laptop – kubeadm is usually run on multiple nodes. The most obvious choice is to rent servers from a cloud provider. However, if there is some spare hardware on your geek shelf – you can repurpose it and build your Kubernetes lab out of it.

**Complicated installation process.** The process of provisioning can be difficult. You need to install kubeadm itself, as well kubectl, container runtime, and a handful of supporting packages.

**Difficult to manage.** Kubeadm is not declarative. You can’t save the applied configuration anywhere. If your node goes away, you will have to bring up a replacement and perform the manual join again(unless you have automated it further). Also, even though the creation process is automated, you will still have to deal with all the burdens related to maintaining a self-hosted Kubernetes cluster (maintaining quorum, backing-up etcd, and so on)

##Steps to deploy
Step 1. Provision your nodes

Step 2. Install kubeadm, kubelet, and kubectl
```
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
```
Step 3. Install container runtime
```
sudo apt-get remove -y docker docker-engine docker.io containerd runc
sudo apt-get update -y
sudo apt-get install -y \
   ca-certificates \
   curl \
   gnupg \
   lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
 "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
 $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl stop containerd
echo "" | sudo tee /etc/containerd/config.toml
sudo systemctl start containerd
```
Step 4. Initialize your cluster (only when creating a new cluster)
```
sudo kubeadm init
```
Step 5. Apply the CNI plugin
```
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
Step 6. For each additional node that you want to join to the existing cluster – repeat steps 2 and 3 and run the kubeadm join command that was output by kubeadm init.
```
#Option 4 – Managed Kubernetes

##Pros
**Production-grade solution.** It’s not the best option, however, some companies use it as a go-to method for provisioning their Kubernetes infrastructure. It can be scaled to a certain extent, however, it requires some extra scripting and configuration.

**Easy to start.** Creating a basic cluster takes seconds. That’s a perfect option when you need to build a cluster quickly.

##Cons
**Require a cloud account.** If you haven’t yet started your cloud journey, this option will require some extra steps to create your cloud account.

**Not maintainable.** The CLI or any script based on CLI is not declarative and does not highlight the state of your infrastructure. This means you will require additional efforts to make sure the automation is applied in an idempotent way.

**Can be expensive.** Managed Kubernetes clusters are relatively expensive. For example, a single Amazon EKS cluster in the us-east-1 region will cost you 73$ dollars per month. So you should never forget to turn down your infrastructure when you are not working with your lab. In AWS you pay not for what you use but for what you have forgotten to terminate.

##Steps to deploy
###To deploy the AWS EKS cluster:
Step 1. Install eksctl: https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html
Step 2. Create a cluster:
```
eksctl create cluster --name my-cluster --region us-east-1
```
Step 3. Generate kubectl credentials and connect to your cluster
```
aws eks update-kubeconfig --name my-cluster –region us-east-1
kubectl get nodes
```
###To deploy the GKE cluster:
Step 1. Enable Google Kubernetes Engine API
Step 2. Create a cluster:
```
gcloud container clusters create example-cluster \
    --zone us-central1-a \
    --node-locations us-central1-a,us-central1-b,us-central1-c
```
Step 3. Generate kubectl credentials and connect to your cluster:
```
gcloud container clusters get-credentials hello-cluster
kubectl get nodes
```
###To deploy the AKS cluster:

Step 1. Create a cluster:
```
az group create --name myResourceGroup --location eastus
az aks create -g myResourceGroup -n myAKSCluster --enable-managed-identity --node-count 1 --enable-addons monitoring --enable-msi-auth-for-monitoring  --generate-ssh-keys
```
Step 2. Generate kubectl credentials and connect to your cluster:
```
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
kubectl get nodes
```
#Option 5 – Install Kubernetes Using Terraform
Terraform is no doubt one of the best Infrastructure as Code tools nowadays. The concept of re-usable modules allows trying new things fast. What you need to do is just clone the module repository and run terraform apply.

##Pros
**Production-grade solution.** Famous brands and large companies rely on Terraform for deploying their critical infrastructure. Terraform provides a huge set of features that allows for managing infrastructure effectively at an enormous scale.

**Perfect maintainability.** Terraform is fully idempotent. It keeps track of resources that it deploys using the state file which can be stored locally or remotely. You can also implement advanced techniques for managing your infrastructure, for example, GitOps.

##Cons
**Require knowledge of Terraform.** If you haven’t worked with Terraform before, you will need some effort to install Terraform and understand how to use it. This makes this option a little challenging for one who is just starting.

**Require a cloud account and can be expensive.** Same as the previous option. Running Kubernetes as a service requires some pre-requisites in terms of cloud and can be costly if you forget to destroy it on time.

##Steps to deploy
###To deploy the EKS cluster, run these commands:
```
git clone https://github.com/hashicorp/learn-terraform-provision-eks-cluster
cd learn-terraform-provision-eks-cluster
terraform init
terraform apply
aws eks --region $(terraform output -raw region) update-kubeconfig \
    --name $(terraform output -raw cluster_name)
kubectl get nodes
```
###To deploy the GKE cluster, run these commands:
```
git clone https://github.com/hashicorp/learn-terraform-provision-gke-cluster
cd learn-terraform-provision-gke-cluster
terraform init
terraform apply
gcloud container clusters get-credentials $(terraform output -raw kubernetes_cluster_name) --region $(terraform output -raw region)
kubectl get nodes
```
###To deploy the AKS cluster, run these commands:
```
git clone https://github.com/hashicorp/learn-terraform-provision-aks-cluster
cd learn-terraform-provision-aks-cluster
terraform init
terraform apply
az aks get-credentials --resource-group $(terraform output -raw resource_group_name) --name $(terraform output -raw kubernetes_cluster_name)
kubectl get nodes
This was an overview of major techniques to install a Kubernetes cluster.
Don’t wait any further, pick an option that you like and start your Kubernetes journey immediately!
```
---
If you enjoyed this article, please support us by sharing it on social networks.

You can find other interesting articles on our blog: https://yourdevopsmentor.com/blog/

Apply for individual mentorship here: https://yourdevopsmentor.com/apply/

Connect with the author on LinkedIn: https://www.linkedin.com/in/vladimir-mukhin-devops/