cka-setup-guide

Setting up Kubernetes in (not so) hard way

Cluster Preparation Guide for CKA

Using kubeadm

K8s

Consideration

Architecture

Steps

1-Create Azure Resources

Azure resources Setup Script

2-Prepare the Virtual Machines

Login to the Client VM using Public IP then connect to the other three Virtual Machines.

Install & Configure [as super user]

Here is the Script

3-Master Node

Here is the Script

Post-setup for master

Follow the instruction given in the outout of the successful setup,

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

4-Join Worker Node

Using the token generated from previous step connect this to the Kubernetes master.

If you forget it then generate a new one by running sudo kubeadm token create --print-join-command

Worker node setup Script

5-Confirm the Setup

Configure the client machine for kubectl

Best Practices It is not recommended to run kubectl in master or worker node. You should run it from outside of the K8s cluster.

In client machine create a folder ~/.kube by

mkdir -p $HOME/.kube

Then copy the ~/.kube/config from master node to client machine using scp

scp config cka@clientIP:$HOME/.kube

Then run this command in client machine

kubectl get nodes 

If the above shows list of nodes and in ready state then we are good to go.

Create a pod to test,

kubectl run nginx --image=nginx

Then check the list of pods

kubectl get pods

6 - Some useful Azure CLI Commands

Get the list of running VMs in a Resource Group

resourceGroup='rg-cka2'
az vm list -d -g $resourceGroup --query "[].{name:name,powerState:powerState}" -o table

Start all the VMs in a Resrouce Group

resourceGroup='rg-cka2'
az vm start --ids $(az vm list -g $resourceGroup --query "[].id" -o tsv)

Stop (deallocate) all the VMs in a Resource Group

resourceGroup='rg-cka2'
az vm deallocate --ids $(az vm list -g $resourceGroup --query "[].id" -o tsv)

7 - Clean up Azure Resources

If you delete the resource group it will delete all the resources inside

# Will ask for confirmation
az group delete -n wriju

# Anyc delete 
az group delete -n wriju --no-wait 

Resources


Prepared and maintained by Wriju Ghosh for CKA Exam playground

Contribute https://github.com/wrijugh/cka-setup-guide

Web https://wrijugh.github.io/cka-setup-guide/

Tested as of 31-August-2021