Kubernetes depuis Docker Compose vol cm secret vol Présentation créée avec Sozi t Boutondroit Boutongauche Boutondu milieu backend-secret.properties 1 2 pass =pass123 api_key =123456789 backend-config.properties 1 2 conf_1 =value1 conf_2 =value2 configmap.yml 1 2 3 4 5 6 7 8 9 10 apiVersion : v1 data : backend-config.properties : | + conf_1=value1 conf_2=value2 kind : ConfigMap metadata : labels : app : backend name : backend secret.yml 1 2 3 4 5 6 7 8 9 10 11 12 13 apiVersion : v1 kind : Secret type : Opaque metadata : labels : app : backend name : backend-29k658kmdk data : backend-secret.properties : cGFzcz1wYXNzMTIzCmFwaV9rZXk9MTIzNDU2Nzg5Cg== # $ echo -n "cGFzcz1wYXNzMTIzCmFwaV9rZXk9MTIzNDU2Nzg5Cg==" | base64 -d # pass=pass123 # api_key=123456789 Comme les configmap mais encodé en base64Pour les données sensible... accès limitéMais attention : pas chiffré, juste encodé Stocke la configuration du service (conteneur),par clef/valeur.La valeur pouvant être le contenu d'un fichier Configmap Décrit des instances de conteneursPermet d'avoir plusieurs réplicasPermet de faire du rolling update orchestrer des conteneurs ing svc pod pod deploy (par exemple) service.yml 1 2 3 4 5 6 7 8 9 10 apiVersion : v1 kind : Service metadata : name : backend spec : ports : - name : http port : 8080 protocol : TCP targetPort : 8080 ingress.yml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 apiVersion : networking.k8s.io/v1 kind : Ingress metadata : name : backend annotations : kubernetes.io/ingress.class : nginx nginx.ingress.kubernetes.io/rewrite-target : /$2 nginx.ingress.kubernetes.io/use-regex : "true" nginx.ingress.kubernetes.io/ssl-redirect : "false" nginx.ingress.kubernetes.io/x-forwarded-prefix : /api spec : rules : - http : paths : - backend : service : name : backend port : number : 8080 path : /api(/|$)(.*) pathType : ImplementationSpecific kubectl.sh 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #!/usr/bin/env bash kubectl config get-contexts kubectl get all --namespace default kubectl get configmaps kubectl scale --replicas=0 deployment/backend kubectl logs -f pods/backend-4215bc kubectl exec -it pods/backend-4215bc -- sh kubectl diff -f deployment.yml kubectl apply -f deployment.yaml kubectl delete -f deployment.yml kubectl diff -k . kubectl apply -k . kubectl delete -k . Introduction à Kubernetesdepuis Docker Compose deployment.yml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 apiVersion : apps/v1 kind : Deployment metadata : name : backend spec : replicas : 1 template : spec : containers : - name : backend image : ubuntu:22.04 env : - name : POSTGRES_USER value : postgres ports : - containerPort : 8080 name : http protocol : TCP volumeMounts : - mountPath : /config name : backend-config - mountPath : /secret name : backend-secret readinessProbe : failureThreshold : 180 httpGet : path : / port : 80 scheme : HTTP resources : requests : memory : 1024Mi cpu : 30m volumes : - name : config-vol configMap : name : backend - name : secret-vol secret : secretName : backend docker-compose.yml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 services : backend : image : ubuntu:22.04 environment : POSTGRES_USER : postgres ports : - 8080:8080 volumes : - ./backend/config:/config - ./backend/secret:/secret healthcheck : test : curl --fail -s http://localhost/ interval : 10s timeout : 5s retries : 20 Avec K8S, le cluster est décritpar différents types d'objets58 types ! Ces YAML représentent des objets. NAME SHORTNAMES APIVERSION NAMESPACED KINDbindings v1 true Bindingcomponentstatuses cs v1 false ComponentStatusconfigmaps cm v1 true ConfigMapendpoints ep v1 true Endpointsevents ev v1 true Eventlimitranges limits v1 true LimitRangenamespaces ns v1 false Namespacenodes no v1 false Nodepersistentvolumeclaims pvc v1 true PersistentVolumeClaimpersistentvolumes pv v1 false PersistentVolumepods po v1 true Podpodtemplates v1 true PodTemplatereplicationcontrollers rc v1 true ReplicationControllerresourcequotas quota v1 true ResourceQuotasecrets v1 true Secretserviceaccounts sa v1 true ServiceAccountservices svc v1 true Servicemutatingwebhookconfigurations admissionregistration.k8s.io/v1 false MutatingWebhookConfigurationvalidatingwebhookconfigurations admissionregistration.k8s.io/v1 false ValidatingWebhookConfigurationcustomresourcedefinitions crd,crds apiextensions.k8s.io/v1 false CustomResourceDefinitionapiservices apiregistration.k8s.io/v1 false APIServicecontrollerrevisions apps/v1 true ControllerRevisiondaemonsets ds apps/v1 true DaemonSetdeployments deploy apps/v1 true Deploymentreplicasets rs apps/v1 true ReplicaSetstatefulsets sts apps/v1 true StatefulSettokenreviews authentication.k8s.io/v1 false TokenReviewlocalsubjectaccessreviews authorization.k8s.io/v1 true LocalSubjectAccessReviewselfsubjectaccessreviews authorization.k8s.io/v1 false SelfSubjectAccessReviewselfsubjectrulesreviews authorization.k8s.io/v1 false SelfSubjectRulesReviewsubjectaccessreviews authorization.k8s.io/v1 false SubjectAccessReviewhorizontalpodautoscalers hpa autoscaling/v2 true HorizontalPodAutoscalercronjobs cj batch/v1 true CronJobjobs batch/v1 true Jobcertificatesigningrequests csr certificates.k8s.io/v1 false CertificateSigningRequestleases coordination.k8s.io/v1 true Leaseendpointslices discovery.k8s.io/v1 true EndpointSliceevents ev events.k8s.io/v1 true Eventflowschemas flowcontrol.apiserver.k8s.io/v1beta2 false FlowSchemaprioritylevelconfigurations flowcontrol.apiserver.k8s.io/v1beta2 false PriorityLevelConfigurationhelmchartconfigs helm.cattle.io/v1 true HelmChartConfighelmcharts helm.cattle.io/v1 true HelmChartaddons k3s.cattle.io/v1 true Addoningressclasses networking.k8s.io/v1 false IngressClassingresses ing networking.k8s.io/v1 true Ingressnetworkpolicies netpol networking.k8s.io/v1 true NetworkPolicyruntimeclasses node.k8s.io/v1 false RuntimeClasspoddisruptionbudgets pdb policy/v1 true PodDisruptionBudgetclusterrolebindings rbac.authorization.k8s.io/v1 false ClusterRoleBindingclusterroles rbac.authorization.k8s.io/v1 false ClusterRolerolebindings rbac.authorization.k8s.io/v1 true RoleBindingroles rbac.authorization.k8s.io/v1 true Rolepriorityclasses pc scheduling.k8s.io/v1 false PriorityClasscsidrivers storage.k8s.io/v1 false CSIDrivercsinodes storage.k8s.io/v1 false CSINodecsistoragecapacities storage.k8s.io/v1 true CSIStorageCapacitystorageclasses sc storage.k8s.io/v1 false StorageClassvolumeattachments storage.k8s.io/v1 false VolumeAttachment sans compter les extensions ! On déclare l'étatdésiré du clusterdans les YAMLqu'on applique avec kubectl : - Démo locale- GCP Deployment Mais on peut se concentrer sur 6 seulement deploy Deployment pod Pod svc Service ing Ingress cm Configmap secret Secret pod Container Pod pod Container Container Pod node Node Cluster pod Container Pod pod Container Container Pod pod Container Pod node Node pod Container Pod node Node Node : serveur physique ou VM sur lequel des pod sont lancés Pod : - plus petite unitée déployable, - groupe de conteneurs partageant les mêmes IP et volumes - contient souvent qu'un seul conteneur Routage réseau vers un service svc Service ing Ingress Permet l'accès à ungroupe de pod par unnom DNS (entre autre) Pour chaque service,nous décrivonsplusieurs objets ! Routageréseau Configurationapplicative Gestion des conteneurs } } } Auteur: Jérémy Soulary pod sur un serveur sur un cluster de serveurs(nombre dynamique) cm secret ing svc pod deploy cm kustomize-output.yml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 apiVersion : v1 data : backend-config.properties : | + conf_1=value1 conf_2=value2 kind : ConfigMap metadata : labels : app : backend name : backend-228mfttkch --- apiVersion : v1 data : backend-secret.properties : cGFzcz1wYXNzMTIzCmFwaV9rZXk9MTIzNDU2Nzg5Cg== kind : Secret metadata : labels : app : backend name : backend-29k658kmdk type : Opaque --- apiVersion : v1 kind : Service metadata : labels : app : backend name : backend spec : ports : - name : http port : 8080 protocol : TCP targetPort : 8080 selector : app : backend --- apiVersion : apps/v1 kind : Deployment metadata : labels : app : backend name : backend spec : replicas : 1 selector : matchLabels : app : backend template : metadata : labels : app : backend spec : containers : - env : - name : POSTGRES_USER value : postgres image : ubuntu:22.04 name : backend ports : - containerPort : 8080 name : http protocol : TCP readinessProbe : failureThreshold : 180 httpGet : path : /health port : 8080 scheme : HTTP resources : requests : cpu : 30m memory : 1024Mi volumeMounts : - mountPath : /config name : backend-config - mountPath : /secret name : backend-secret volumes : - configMap : name : backend-228mfttkch name : config-vol - name : secret-vol secret : secretName : backend-29k658kmdk --- apiVersion : networking.k8s.io/v1 kind : Ingress metadata : annotations : kubernetes.io/ingress.class : nginx nginx.ingress.kubernetes.io/rewrite-target : /$2 nginx.ingress.kubernetes.io/ssl-redirect : "false" nginx.ingress.kubernetes.io/use-regex : "true" nginx.ingress.kubernetes.io/x-forwarded-prefix : /api labels : app : backend name : backend spec : rules : - http : paths : - backend : service : name : backend port : number : 8080 path : /api(/|$)(.*) pathType : ImplementationSpecific Kubernetes depuis Docker Compose
1
  1. Intro+help
  2. orchestrer
  3. docker compose
  4. dcp vs deployment
  5. objet yaml
  6. 58 types d'objets K8S
  7. 6 types principaux
  8. Cluster
  9. Deployment
  10. Configmap
  11. Secret
  12. Deployment full
  13. Service
  14. Ingress
  15. réseau
  16. pour chaque service
  17. kubectl
  18. démo
  19. vue globale