curl -fsSL https://get.docker.com -o get-docker.shsh get-docker.sh
containerd
doesn’t have CRI disabledEdit the file /etc/containerd/config.toml
and make sure that the disabled_plugins setting is blank.
nano /etc/containerd/config.toml
Then restart the containerd
service:
service containerd restart
We'll start by installing the apt-transport-https
package which enables working with http
and https
in Ubuntu’s repositories. Also, install curl
as it will be necessary for the next steps. Execute the following command:
sudo apt install apt-transport-https curl
Then, add the Kubernetes signing key to both nodes by executing the command:
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" >> ~/kubernetes.listsudo mv ~/kubernetes.list /etc/apt/sources.list.dcurl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
After that, update the nodes:
sudo apt update
Once the update completes, we will install Kubernetes. This involves installing the various tools that make up Kubernetes: kubeadm
, kubelet
, kubectl
, and kubernetes-cni
.
sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni
Our nodes must have a unique hostname for easier identification. If we are deploying a cluster with many nodes, we can set it to identify names for our worker nodes such as node-1
, node-2
, etc. As we had mentioned earlier, we have named our nodes kubernetes-master
and kubernetes-worker
. We have set them at the time of creating the server. However, you can adjust or set yours if you had not already done so from the command line. To adjust the hostname on the master node, run the following command:
sudo hostnamectl set-hostname kubernetes-master
On both master and worker nodes, update the cgroupdriver
with the following commands:
sudo mkdir /etc/dockercat <<EOF | sudo tee /etc/docker/daemon.json{ "exec-opts": ["native.cgroupdriver=systemd"],"log-driver": "json-file","log-opts":{ "max-size": "100m" },"storage-driver": "overlay2"}EOF
Then, execute the following commands to restart and enable Docker on system boot-up:
sudo systemctl enable dockersudo systemctl daemon-reloadsudo systemctl restart docker
The first step in deploying a Kubernetes cluster is to fire up the master node. While on the terminal of your master node, execute the following command to initialize the kubernetes-master
:
kubeadm init --pod-network-cidr=10.244.0.0/16 --control-plane-endpoint <EXTERNAL-IP>
In the output, Kubernetes also displays some additional commands that you should run as a regular user on the master node before you start to use the cluster. Let’s run these commands:
mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config
We have now initialized the master node. However, we also have to set up the pod network on the master node before we join the worker nodes.
A pod network facilitates communication between servers and is necessary for the proper functioning of the Kubernetes cluster. You can read more about Kubernetes Cluster Networking from the official docs. We will be using the Flannel pod network for this tutorial. Flannel is a simple overlay network that satisfies the Kubernetes requirements.
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlkubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
First, log into the worker node on a separate terminal session. Use the kubeadm
join command that was shown in the terminal when we initialized the master node in Step 7, execute the command indicated there, it will look something like the following:
kubeadm join XXXX:6443 --token XXX \--discovery-token-ca-cert-hash sha256:XXXX
Once the joining process completes, switch the master node terminal and execute the following command to confirm that your worker node has joined the cluster:
kubectl get nodes
Free Resources