Configurare un cluster Kubernetes

Da It Ikoula wiki.
Jump to navigation Jump to search

it:Configurare un cluster Kubernetes fr:Deployer un cluster Kubernetes

Cosa è Kubernetes ?

Kubernetes è una piattaforma open-sorce che si pone l’obiettivo di gestire i carichi di lavoro e dei servizi containerizzati. Permette di di configurare manualmente e in maniera automatica. Kubernetes è un grande ecosistema in rapida espansione. Questa procedura vi permetterà di impostare rapidamente e facilmente un cluster Kubernetes (k8s) di tre nodi a partire da tre istanze CentOS 7 della stessa rete.

Una di queste 3 istanze sarà il nostro nodo principale e le altre due saranno i nostri nodi operativi. Riassumendo, il nodo principale è quello dal quale gestiamo il cluster Kubernetes (orchestrator container) dalla sua API e i nodi worker sono quelli su cui verranno eseguiti i pod, ovvero i container (Docker nel nostro caso).

Partiamo dal principio che le nostre 3 istanze CentOS 7 sono già installate e che eseguiamo l’accesso in SSL, queste sono condizioni assolutamente necessarie.

Ecco la configurazione che abbiamo nel nostro esempio :

Node master : "k8s-master" / 10.1.1.16
Premier node worker : "k8s-worker01" / 10.1.1.169
Second node worker : "k8s-worker02" / 10.1.1.87

Preparazione del sistema et installazione di Kubernetes tutorial

Le azioni che seguono sono da effettuare in tutte le instanze (master e workers) come root.

Comincia con il riempire il file /etc/hosts su ognuna delle vostre instanze.

Nel nostro esempio ecco il file per le nostre 3 istanze :

    cat /etc/hosts 
    127.0.0.1 localhost 
    ::1 localhost 
 
    10.1.1.16 k8s-master
    10.1.1.169 k8s-worker01
    10.1.1.87 k8s-worker02


Attiva il modulo bridge e le regole iptables per quest'ultimo tramite i seguenti tre comandi:

    modprobe bridge 
    echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf 
    sysctl -p /etc/sysctl.conf    


Aggiungi il repository YUM Docker :

    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       


Installa Docker :

    yum install -y docker-ce

    Poi installa i package Kubernetes necessari :
    yum install -y kubeadm kubelet kubectl


Modifica il file di configuarzion di systemd kubelet (/etc/systemd/system/kubelet.service.d/10-kubeadm.conf) per aggiungere la seguente riga nella sezione « [Servizio] » :

    Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"   


Come :

    cat /etc/systemd/system/kubelet.service.d/10-kubeadm.conf 
    # Note: This dropin only works with kubeadm and kubelet v1.11+ 
    [Service] 
    Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf" 
    Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml" 
    *Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"* 
    # This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env 
    # This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use 
    # the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
    EnvironmentFile=-/etc/sysconfig/kubelet 
    ExecStart= 
    ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS


Ricarica le impostazioni, attiva e poi riavvia i servizi docker e kubelet attraverso i tre comandi seguenti :

    systemctl daemon-reload 
    systemctl enable docker kubelet 
    systemctl start docker kubelet


Disattiva la swap del sistema( kubelet non supporta la memoria swap) :

    swapoff -a


Ricorda di commentare ed eliminare le linee inerenti alla swap nel file /etc/fstab di ognuno delle vostre istanze come di seguito :

    #/dev/mapper/vg01-swap swap swap defaults 0 0