Skip to content

Instantly share code, notes, and snippets.

@matteyeux
Last active February 14, 2020 16:58
Show Gist options
  • Save matteyeux/58b6d4994e2062c1a781f3643c262eef to your computer and use it in GitHub Desktop.
Save matteyeux/58b6d4994e2062c1a781f3643c262eef to your computer and use it in GitHub Desktop.

Installation de Kubernetes

Installation de kubernetes en mode cluster pour ISR-ORC4.

Prérequis

  • 2G de RAM pour chaque machine
  • 1 Socket, 2 coeurs
  • Swap désactivé (sudo swapoff -a + edit de /etc/fstab)
  • Docker CE

Installation des repos et paquets pour kubernetes :

sudo apt update && apt install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

Creation du cluster

Initialisation du cluster : sudo kubeadm init --pod-network-cidr=192.168.0.0/16

Cela va prendre quelques minutes, puis quand c'est fini on se retrouve ce message :

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.82.133:6443 --token lgs01l.kyn05zx7er5as9rg \
    --discovery-token-ca-cert-hash sha256:c0ba2468775f71b9453711aad330d3a258b2a0166ee329c659af1784886622e7 

Sur le master il faut taper les commandes suivantes:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

On va créer un dossier dans le $HOMEDIR de notre utilisateur et lui donner les droits sur le fichier de conf.

Puis il faut ajouter les workers au cluster avec cette commande en tant que root:

kubeadm join 192.168.82.133:6443 --token lgs01l.kyn05zx7er5as9rg \
    --discovery-token-ca-cert-hash sha256:c0ba2468775f71b9453711aad330d3a258b2a0166ee329c659af1784886622e7

Création d'un réseau pour les nodes

On va utiliser calico pour créer ce réseau pour node : sudo kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/calico.yaml

Par défaut le réseau créé par la conf de calico est 192.168.0.0/16. Il faut éditer la conf si on veut spécifier un réseau différent. Pour ORC4 je vais rester sur ce réseau.

Premier pod

On lance un premier pod, avec un serveur httpd. kubectl va dire que la méthode est dépréciée donc il faudra voir ce que dis la doc à ce sujet. kubectl run my-httpd --image=httpd --replicas=1 --port=80

Si tout s'est bien passé, avec get deploy le pod est dispo :

mathieu@master:~$ kubectl get deploy
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
my-httpd   1/1     1            1           61s

Avec en spécifiant l'option wide on peut récuperer l'IP du pod pour tester le réseau. mathieu@master:~$ kubectl get deploy -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR my-httpd 1/1 1 1 89s my-httpd httpd run=my-httpd

Depuis un des workers :

mathieu@worker2:~$ curl 192.168.189.66
<html><body><h1>It works!</h1></body></html>

On arrive à faire une requete sur le pod qui a été deployé.

Client kubctl

Le client installé sur notre machine est optionel, on peut aussi le gerer des le (ou les) master(s).

Depuis le master on récupère le fichier de conf de kube : ~/.kube/config. Ne pas oublier de modifer le hostname ou l'IP dans le fichier de conf. Pour éviter que le client vérifie le certificat TLS : Then disable TLS check :

kubectl config set-cluster kubernetes --insecure-skip-tls-verify=true

J'imagine qu'on peut aussi ajouter le host dans /etc/hosts (mais pas essayé)

Lancer une commande

$ kubectl exec my-httpd-6f58b78d74-njfvz ls
bin
build
cgi-bin
conf
error
htdocs
icons
include
logs
modules

S'attacher à un container

$ kubectl attach my-httpd-6f58b78d74-njfvz 
Defaulting container name to my-httpd.
Use 'kubectl describe pod/my-httpd-6f58b78d74-njfvz -n default' to see all of the containers in this pod.
If you don't see a command prompt, try pressing enter.

ressources :

@AHPanna
Copy link

AHPanna commented Feb 10, 2020

System : Debian 10

i had some issues to run kubeadm and make sure that you copy correctly the /etc/kubernetes/admin.conf $HOME/.kube/config, for check if kubectl did get a handshake then do a kubectl cluster-info, you should get the master node information.
for kubeadm got some errors like there was some port was used for no reason i added this parameters at then end to --ignore-preflight-errors=All to fix,
kubeadm join 192.168.82.133:6443 --token lgs01l.kyn05zx7er5as9rg --discovery-token-ca-cert-hash sha256:c0ba2468775f71b9453711aad330d3a258b2a0166ee329c659af1784886622e7 --ignore-preflight-errors=All .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment