To install Kubernetes on a single machine, you can follow the steps below:
- Install Docker:
sudo apt-get update
sudo apt-get install docker.io
- Install kubeadm, kubelet and kubectl:
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
- Initialize the cluster:
sudo swapoff -a # if swap is enabled, disable it to prevent issues with kubelet.
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 # replace pod network CIDR as per your requirement.
- Set up kubectl configuration:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Deploy a pod network to the cluster:
You can choose from different pod network providers like Flannel, Calico, etc.
For example, to deploy Flannel:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- Check if all nodes are ready:
kubectl get nodes
You should see one node in Ready
state.
That’s it! Your Kubernetes cluster is now set up on a single machine!