Kubernetes is a popular open-source platform for managing containerized applications. It is widely used for automating the deployment, scaling, and management of containerized applications. Ubuntu is a popular Linux distribution that is often used as the operating system for servers and workstations.
When it comes to installing Kubernetes on Ubuntu, there are several options available. One common approach is to use the Kubernetes official package repository, which provides packages for all major Ubuntu releases. Another option is to use a tool like kubeadm, which simplifies the installation process and can be used to set up a Kubernetes cluster on Ubuntu.
Install Docker
sudo apt-get install \
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
sudo chmod a+r /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
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo groupadd docker
sudo usermod -aG docker $USER
Enable container runtime options
sudo modprobe overlay
sudo modprobe br_netfilter
Add some settings to sysctl
sudo tee /etc/sysctl.d/kubernetes.conf<<EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 EOF
sudo sysctl --system
Curl needed to download scripts( Optional) to install kubectl
sudo apt install curl -y
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
chmod +x kubectl
kubectl version --client --output=yaml
Installing kubernetes cluster using kubeadmn scripts
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 systemctl enable kubelet
kubectl get nodes
kubectl cluster-info
sudo apt-mark hold kubelet kubeadm kubectl
docker ps
sudo kubeadm init --control-plane-endpoint 172.16.0.132 --pod-network-cidr=10.0.0.0/16
can use multiple options including --apiserver-advertise-address
For adding multiple control plane endpoints (optional)
kube admin multiple endpoint --control-plane-endpoint=cluster-endpoint
You should see the following screen once initiated:
Your Kubernetes control-plane has initialized successfully!
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
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:
kubeadm join 172.16.0.132:6443 --token j0gvgd.yfdxvwvh0jlpyted \
--discovery-token-ca-cert-hash sha256:3f16dbc99246b4565880566a0839dd15662b0d59fb123c83e8723be095c91214 \
--control-plane
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 172.16.0.132:6443 --token j0gvgd.yfdxvwvh0jlpyted \
--discovery-token-ca-cert-hash sha256:3f16dbc99246b4565880566a0839dd15662b0d59fb123c83e8723be095c91214
Run below commands to manage kubernetes using normal user
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
If root-user , Run below command
export KUBECONFIG=/etc/kubernetes/admin.conf
To add multiple control plane use ( token should be as per the cluster )
kubeadm join 172.16.0.132:6443 --token j0gvgd.yfdxvwvh0jlpyted \
--discovery-token-ca-cert-hash sha256:3f16dbc99246b4565880566a0839dd15662b0d59fb123c83e8723be095c91214 \
--control-plane
To add nodes use below commands
kubeadm join 172.16.0.132:6443 --token j0gvgd.yfdxvwvh0jlpyted \
--discovery-token-ca-cert-hash sha256:3f16dbc99246b4565880566a0839dd15662b0d59fb123c83e8723be095c91214
Run below command to get cluster info
kubectl cluster-info
Network driver installation
Network driver will not be present by default , initaite it manually
to Initiate manually select from one of the driver available and run respective commands
I am using calcio
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Run below commands to install calcio
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.1/manifests/tigera-operator.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.1/manifests/custom-resources.yaml
watch kubectl get pods -n calico-system
verify the installation and proceed
kubectl get nodes -o wide
Run following command to get all namespaces pods
watch kubectl get pods --all-namespaces
If the token is expired or removed. You can create token manually by running:
kubeadm token create --print-join-command
Your Cluster is now ready