Kubernetes Cluster Setup
A Kubernetes cluster is a set of node machines for running containerized applications. If you’re running Kubernetes, you’re running a cluster.
At a minimum, a cluster contains a control plane and one or more compute machines, or nodes.
The control plane is responsible for maintaining the desired state of the cluster, such as which applications are running and which container images they use.
Nodes actually run the applications and workloads.
Key advantage of kubernetes cluster are:
- the ability to schedule and run containers across a group of machines, be they physical or virtual, on-premises or in the cloud.
- Kubernetes containers aren’t tied to individual machines.
- Rather, they’re abstracted across the cluster.
Steps for Kubernetes cluster setup
- The machine needs to have 2 CPU processors and all the machines in the cluster should be in the same network so that they can ping each other
- ssh into all the VMS
- In all the node swap memory should be disabled
to check current status use the below command
to disable swap memory
Now, make these changes in fstab so after boot, the swap memory will be disabled
comment all swap related lines(repeat this process in all the nodes)
- Now install Docker in all the nodes
Open the k8 document and check which current docker version is supported by the k8s
- Install Kubeadm in all the VMS
Check the outcome of the below command in all the nodes, it should be different in all the nodes
sudo cat /sys/class/dmi/id/product_uuid
Now use the below commands to install and update necessary packages
Update the apt package index and install packages needed to use the Kubernetes apt repository:
sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl
Download the Google Cloud public signing key:
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
Add the Kubernetes apt repository:
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
Update apt package index, install kubelet, kubeadm, and kubectl, and pin their version:
sudo apt-get update sudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl
- To initialize the control-plane node run(to create master node use below command on any of the nodes)
kubeadm init --pod-network-cidr=10.244.0.0/16
this will be a ip range of pods.
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
To check the installation of master use below command
kubectl get nodes
You should be able to see one node.
You should now deploy a Pod network to the cluster.with one of the options listed at: /docs/concepts/cluster-administration/addons/
Run "kubectl apply -f [podnetwork].yaml"
You can now join any number of machines by running the following on each node as root:
kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>