Cluster Preparation Guide for CKA
Using kubeadm
- Virtual Machines are created in Azure under Azure VNet
- One client machine has Public IP others are Private
- IP Range
- Docker
- Kubeadm
- One master VM
- Weaver as Pod network plugin
- Two Worker VM
- One Client VM with Public IP
- Resource Group
- Storage Account (optional)
- Virtual Network
- Subnet
- NIC
- Public IP Address
- Three Virtual Machines (for Kubernetes)
- One Virtual machine as client to connect the K8s cluster
Azure resources Setup Script
Login to the Client VM using Public IP then connect to the other three Virtual Machines.
Install & Configure [as super user]
- IP tables
- Docker
- Kubectl, Kubeadm, Kubelet
Here is the Script
Here is the Script
Post-setup for master
Follow the instruction given in the outout of the successful setup,
- Copy kubeconfig to the folder
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Copy the
kubeadm join
command - Install the pod network plugin
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
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
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
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)
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
- Kubeadm Installation
- Docker Installation
- Weaver Installation
- CKA Exam Curriculum
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