Skip to content

Instantly share code, notes, and snippets.

@khurdz
Last active October 29, 2018 12:41
Show Gist options
  • Save khurdz/471080e587b6e1e69c63792f64b7ae10 to your computer and use it in GitHub Desktop.
Save khurdz/471080e587b6e1e69c63792f64b7ae10 to your computer and use it in GitHub Desktop.
Formation Kubernetes 10/2018

Kubernetes

Composants

  • Nodes (Master / Worker)
  • API Server, etcd
  • Scheduler
  • Kubelet (agents)
  • Controllers

Minikube

  • Environnement de développement et de tests en local
  • VirtualBox
  • Install
  • kubectl pour dialoguer avec le cluster k8s
  • Config
  • Auto-completion
  • Minishift pour l'équivalent OpenShift

Concepts

Pods

  • Ensemble de containers
  • Même namespace et cgroup, même configuration réseau
  • Cohabitation de plusieurs containers différents (démarrant en même temps)
  • Status : pending, running, succeeded, failed, unknown)
  • RestartPolicy (restart, onfailure, never)
  • Définition de Healthchecks pour chaque container du pod (http, tcp, exec)
    • Liveness (runtime)
    • Readiness (init)
  • Options d'ordonnancement disponibles (dependances intra-pod)
    • Container d'initialisation
    • Un container lance une tâche en préambule du démarrage du pod (configuration, téléchargement de données...)

Déclaration YAML

  • Décrit l'état attendu
    • Pod
    • Deployment
    • Service
    • LoadBalancer
    • ...
  • Clés principales
    • apiVersion
    • kind
    • metadata
    • spec

Deployments

  • Gestion de pods
  • Différents types de controllers, dont les Deployments
  • Définition de pods
    • replicas
    • labels
    • update/rollback/scaling

Services

  • Un ou plusieurs pods
  • Un ou plusieurs ports
  • NAT
  • Sélection via les labels
  • kube-proxy (contacte le pod le plus proche) & iptables
  • DNS
  • Différents types :
    • ClusterIP (interne)
    • LoadBalancer
      • IP publique
      • Hébergé par Cloud Providers, drivers spécifiques...
    • Ingress
      • On-prem via traefik, nginx, haproxy, F5...
      • Redirection vers les bons domaines
      • Porté en tant que service dans un namespace spécifique (!= kube-system)
      • Manifeste qui déclare les redirections à effectuer
      • RP dans namespace kube-system (haproxy, nginx...) écoute les ingress et se reconfigure automatiquement
    • NodePort

Volumes

  • Différents cycles de vie
    • Ephémères
      • Supprimé en même temps que le pod
      • Permet l'échange de fichiers temporaires au sein d'un pod, le cache de fichiers en tmpfs
    • Persistents
  • Différents stockages
    • Local (attachement local, HA/LB impossible, + rapide, utile pour les journaux, le cache)
    • Distribué (pas d'attachement, HA/LB possible, - rapide, utile pour le téléchargement, fichiers générés...) : NFS, GlusterFS, Ceph, iSCSI
  • Storage > StorageClass > PersistentVolumeClaim > PersistentVolume > Pod

ReplicaSets

  • Controllers créés par un déploiement pour gérer la scalabilité

Jobs

  • Controllers créant des pods dans le cadre de tâches oneshot (indexation, calcul)
  • Parallélisables

CronJobs

  • Jobs planifiés
  • Date UTC (clusters world wide)
  • ConcurrencyPolicy (allow, forbid, replace)

DaemonSets

  • Permet de démarrer un pod sur chaque noeud du cluster
  • Possibilité de sélectionner les noeuds
  • Utile pour le monitoring, gestion de journaux (logstash), outils de volumes (glusterd)

Secrets

  • Stockent des informations sensibles (password, clés ssh, tokens)
  • Version-controlled
  • Géré par k8s
  • Exposé sur les pods (volumes, envvars)

Déploiement d'une Infra avec Kubespray

  • Vagrant (crée des VM pour simuler une infra complète)
  • Ansible
  • RBAC

Tips

Oh My ZSH

Markdown

  • Marp

Vim

Labs

Lab#1

minikube dashboard
kubectl cluster-info
cat .kube/config
kubectl config get-contexts
kubectl run hello-world --image=pockost/http-helloworld --port=8080
kubectl get deployments
kubectl describe deployment hello-world
kubectl expose deployment hello-world --type=LoadBalancer
kubectl describe deployment hello-world
kubectl get services # (address 'pending' cause of minikube)
minikube service list
minikube dashboard &
minikube docker-env
eval $(minikube docker-env) # pour lancer un docker build en local mais exécuté sur le noeud minikube distant
git clone https://github.com/pockost/docker-http-helloworld
cd docker-http-helloworld/
vi server.js
docker build -t baptiste-http-helloworld:v1 .
docker images
kubectl run hello-world-baptiste --image=baptiste-http-helloworld:v1 --port=8080
kubectl get deployments
kubectl expose deployment hello-world-baptiste --type=LoadBalancer
kubectl get services
minikube service hello-world-baptiste
kubectl logs -f hello-world-baptiste-96fc6f9c8-9v66c
minikube ssh
minikube addons list
minikube addons enable efk
minikube addons enable metrics-server
minikube addons enable heapster
minikube service list

Lab#2

kubectl get pod -o wide
# possible de ne faire qu'un seul fichier pour décrire pod/deployments/services
kubectl expose pod grafana --type=LoadBalancer (containerPorts + labels)
# en pratique, on créera plutôt directement un Deployment pour exposer un port
kubectl get deployment -o json
kubectl get svc -o yaml

Lab#3-4-5

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