NFS (Network File System) Storage for Persistent volume claim part 1

Once you have created your Kubernetes cluster it’s time to handle persistent volumes and one way to store your data in a common safe place for all your Kubernetes services is an NFS storage.

About NFS Mount Volumes

NFS mounts work to share a directory between several servers. This has the advantage of saving disk space, as the home directory is only kept on one server, and others can connect to it over the network. When setting up mounts, NFS is most effective for permanent fixtures that should always be accessible.

Lest do it with a new VM.

  • Create a small new VM “Standard B1s (1 vcpus, 1 GiB memory)”
  • Ensure the volume storage is enough for your purposes
  • Ensure this new machine is accessible through your network

Time to set up the NFS Host

Ubuntu

sudo apt-get update sudo apt-get install nfs-kernel-server

Centos

yum install nfs-utils nfs-utils-lib 
chkconfig nfs on  
service rpcbind 
start service nfs start

Subsequently, run several startup scripts for the NFS server

Now we will create the shared directory

Ubuntu and Centos

sudo mkdir /var/nfs/general 

Next, we’ll dive into the NFS configuration file to set up the sharing of these resources.

nano /etc/exports 
#add this for each folder you want to share 
/var/nfs/general 10.1.6.4(rw,sync,no_root_squash,no_subtree_check)

These settings accomplish several tasks:

  • rw: This option allows the client server to both read and write within the shared directory
  • sync: Sync confirms requests to the shared directory only once the changes have been committed.
  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
  • no_root_squash: This phrase allows root to connect to the designated directory

Note: we need to add the IP of each server we want to share the NFS

Finally, in Centos run

exportfs -a

and Ubuntu

sudo systemctl restart nfs-kernel-server

Setting Up the NFS Client

Step One—Download the Required Software

Start off by using apt-get to install the NFS programs.

Centos yum install nfs-utils nfs-utils-lib

Ubuntu: sudo apt-get update

sudo apt-get install nfs-common

Step Two—Mount the Directories

Once the programs have been downloaded to the client-server, create the directory that will contain the NFS shared files mkdir -p /mnt/nfs/home

Then go ahead and mount it

mount 10.1.6.6:/var/nfs/general  /mnt/nfs/home

You can use the df -h command to check that the directory has been mounted. You will see it last on the list.

df -h

BAJAR LA VERSION DE KUBERNETES EN UN CLUSTER BASE CENTOS 7

En algunas ocaciones tenemos que hacer downgrade de la versión del cliente y el servidor de kubernetes debido a diferentes incompatibilidades con utilidades como Istio, Helm, etc.

Si partimos de que armamos nuestro cluster on prem o simplemente no estamos usando el servicio de kubernetes de alguna de las nubes como Azure, GCP o AWS. esta guía puede ser útil.

Lo primero es saber que versión tenemos corriendo en el cluster

kubectl version --short
Client Version: v1.14.8
Server Version: v1.14.8
sudo docker rm `docker ps -a -q`
sudo docker rmi `docker images -q`
sudo kubeadm reset 
sudo yum remove kubeadm kubectl kubelet kubernetes-cni kube*    
sudo yum autoremove 
sudo rm -rf ~/.kube

En Centos la clave es desinstalar por completo la versión de kubernetes por lo cual debemos escribir en la terminal preferentemente como root:

En este caso vamos a eliminar todas los contenedores del cluster y vamos a hacer lo mismo con las imágenes y para asegurarnos hacemos de forma opcional : Docker System prune -all para asegurarnos:

$ docker system prune --all  
WARNING! This will remove:    - all stopped containers    - all networks not used by at least one container    - all images without at least one container associated to them    - all build cache    Are you sure you want to continue? [y/N]  

Esto deberíamos aplicarlo a los nodos del cluster… Una vez este realizada esta acción vamos a realizar nuevamente la instalación de kubernetes en Centos desde.

Instalación de kubernetes.

 cat  <<EOF > /etc/yum.repos.d/kubernetes.repo
 [kubernetes]
 name=Kubernetes
 baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
 enabled=1
 gpgcheck=1
 repo_gpgcheck=1
 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
 EOF 

Con esto básicamente estamos agregando las rutas para poder hacer yum Install sin embargo la versión deseada no se especifica en estos repos si no desde la ejecución del comando yum.

yum install -y kubelet-<version> kubectl-<version> kubeadm-<version>
ejemplo: yum install -y kubelet-1.8.1 kubectl-1.8.1 kubeadm-1.8.1 kubernetes-cni-0.5.

Terminamos con el resto de la instalación :

$systemctl enable kubelet
$systemctl start kubelet
# y finalmente solo revisamos que la versión sea la que necesitamos
$kubectl version --short

Hasta este punto este procedimiento se hace en los nodos y el maestro

Solo para el nodo Master:

kubeadm init --pod-network-cidr=10.244.0.0/16
Aquí es necesario copiar el kubeadm join a los nodos por lo que se copia y pega el comando en cada uno.

Finalmente para acceder al cluster con un usuario diferente al root:

[cloud_user@clustercentos ~]$ mkdir -p $HOME/.kube
[cloud_user@clustercentos ~]$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[cloud_user@clustercentos ~]$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

El resto es deplorar los servicios que se esperan tener en el cluster con kubectl apply -f ejemplo.yaml