In a previous post, we've reviewed the process to install kubernetes locally on an Ubuntu development machine. However, since the change in kubernetes to deprecate docker, things changed. In addition, due to purpose of dynamically supporting various CRIs, the process is poorly documented.
To automate the installation, we will provide 3 different scripts:
- Installation of the kube* binaries
- Installation of Container Runtime Interface (CRI)
- Installation of the kubernetes cluster
To install the kube* binaries we use the following:
echo "Update the apt"
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
echo "Download the GCP signing key"
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "Add the Kubernetes apt repo"
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
echo "Update kube* binaries"
sudo apt-mark unhold kubelet kubeadm kubectl
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark unhold kubelet kubeadm kubectl
echo "Update kubectl manually"
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
rm kubectl
To install the CRI we use the following:
# Install docker
sudo apt-get remove -y docker docker-engine docker.io containerd runc
sudo apt-get autoremove -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --batch --yes --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.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 -y
sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Install docker CRI adapter
rm -rf ./cri
mkdir ./cri
CRI_VERSION=$(curl -s https://api.github.com/repos/Mirantis/cri-dockerd/releases/latest|grep tag_name | cut -d '"' -f 4)
wget https://github.com/Mirantis/cri-dockerd/releases/download/${CRI_VERSION}/cri-dockerd-${CRI_VERSION}-linux-amd64.tar.gz -P ./cri
wget https://raw.githubusercontent.com/Mirantis/cri-dockerd/master/packaging/systemd/cri-docker.service -P ./cri
wget https://raw.githubusercontent.com/Mirantis/cri-dockerd/master/packaging/systemd/cri-docker.socket -P ./cri
tar xvf ./cri/cri-dockerd-${CRI_VERSION}-linux-amd64.tar.gz -C ./cri
sudo mv ./cri/cri-dockerd /usr/local/bin/
sudo mv ./cri/cri-docker.socket ./cri/cri-docker.service /etc/systemd/system/
sudo sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
sudo systemctl daemon-reload
sudo systemctl enable cri-docker.service
sudo systemctl enable --now cri-docker.socket
rm -rf ./cri
Notice that the CRI installation includes both the CRI installation itself, that is, the docker installation, and the adapter installation, which glues the docker CRI to kubernetes APIs.
Finally to install the kubernetes cluster, we use the following:
# Remove cluster
sudo rm -rf $HOME/.kube
sudo rm -rf /var/lib/etcd
sudo rm -rf /etc/cni/net.d
sudo kubeadm reset -f --cri-socket /run/cri-dockerd.sock
# Install cluster
sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --cri-socket /run/cri-dockerd.sock
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl taint nodes --all node-role.kubernetes.io/control-plane- node-role.kubernetes.io/master-
# Install calico
curl https://docs.projectcalico.org/manifests/calico.yaml -O
kubectl apply -f calico.yaml
rm -f calico.yaml
# Install Helm
rm -rf ~/.helm
sudo rm -rf /usr/local/bin/helm
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh
rm ./get_helm.sh
This includes also the Container Network Interface installation (CNI), which is this case we use calico, and an optional, but mostly required, installation of helm.
No comments:
Post a Comment