Monday, January 3, 2022

Installing Kubernetes on your Development Machine

 


I hear many developer that are using minikube to run kubernetes on their development machine.

Working on your local kubernetes during development stage can in many cases shorten development life-cycle, due to ability to quickly observe end to end behavior of the system. However, using minikube does not seems like the right way to do it. Minikube use a VM running on the development machine, hence the performance of the kubernetes cluster, and the load on the development machine are high.

Instead of using minikube, a good alternative is to install a bar metal kubernetes on the development machine. It might talk a bit longer to install, but the simplicity and performance of it sure make this method way better.


To install the kube* binaries on the development machine use the following script:


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-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl



To install kubernetes on the development machine, we can use the following script:



# Install cluster
sudo rm -rf $HOME/.kube
sudo rm -rf /var/lib/etcd
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
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/master-

# Install calico
curl https://docs.projectcalico.org/manifests/calico.yaml -O
kubectl apply -f calico.yaml
rm -f calico.yaml



If we're already using a script, why not install other requirements as well, such as Helm:



# 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



And you can go on and add other requirements for your application as part of this cluster, such as metrics server, or anything you might require on the kubernetes cluster.





No comments:

Post a Comment