Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers. This guide will walk you through the steps to set up Kubernetes on a Linux server.
Before you begin, ensure you have the following:
Kubernetes uses Docker to manage containers. First, Install Docker.
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 -
sudo bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF'
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Initialize your Kubernetes cluster using kubeadm
:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
After initialization, set up the local kubeconfig:
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 allow communication between cluster nodes. For example, using Flannel:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
To add worker nodes to your cluster, run the following command on each worker node (replace <token>
and <master-ip>
with your actual token and master IP):
sudo kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>