Differences

This shows you the differences between two versions of the page.

Link to this comparison view

devops:laboratoare:05 [2021/05/24 17:37]
127.0.0.1 external edit
devops:laboratoare:05 [2021/07/28 16:54] (current)
bogdan.croitoru
Line 1: Line 1:
-===== Laboratorul 05. =====+===== Laboratorul 05. Kubernetes ​=====
  
 +==== 5.1. Pods ====
 +
 +<note tip>​Nota:​ pe parcursul laboratoarelor de mai jos, va rog sa inlocuiti **"​id"​** cu numarul aferent fiecarui student.</​note>​
 +
 +  * Adaugam credentialele pentru clusterul de kubernetes
 +
 +<​note>​mkdir ~/.kube
 +
 +cp config ~/.kube
 +
 +kubectl get nodes</​note>​
 +
 +  * Observam contextul actual folosit
 +  * Verificam conexiunea si observam contextul folosit
 +
 +<​note>​kubectl config view</​note>​
 +
 +  * Creare namespace student.
 +
 +  * Fiecare student isi va crea propriul namespace, folosind id-ul student aferent.
 +
 +<​note>​kubectl create ns student[id]
 +
 +kubectl get ns</​note>​
 +
 +  * Configuram kubectl sa foloseasca ca namespace implicit namespace-ul propriu.
 +
 +<​note>​kubectl config set-context --current --namespace=student[id]
 +
 +kubectl config view</​note>​
 +
 +  * Editam fisierul "​pod01.yaml"​ cu id-ul aferent fiecarui student, apoi creem un pod conform definitiei din fisier. Pod-ul se va crea in aproximativ 10 secunde. Observati output-ul celor doua comenzi get. Folositi id-ul aferent.
 +
 +<​note>​kubectl apply -f pod01.yaml
 +
 +kubectl get pods 
 +
 +kubectl get pods webserver-student-id -owide
 +
 +kubectl get pods webserver-student-id -oyaml
 +</​note>​
 +
 +  * Intram in pod-ul nou creat si observam.
 +
 +<​note>​kubectl exec -it webserver-student-id -- bash</​note>​
 +
 +<​note>​root@webserver-student-id:/#​ cat /​etc/​os-release
 +
 +PRETTY_NAME="​Debian GNU/Linux 10 (buster)"​
 +
 +NAME="​Debian GNU/​Linux"​
 +
 +VERSION_ID="​10"​
 +
 +VERSION="​10 (buster)"​
 +
 +VERSION_CODENAME=buster
 +
 +ID=debian
 +
 +HOME_URL="​https://​www.debian.org/"​
 +
 +SUPPORT_URL="​https://​www.debian.org/​support"​
 +
 +BUG_REPORT_URL="​https://​bugs.debian.org/"​
 +
 +root@webserver-student-id:/#​ exit
 +
 +kubectl logs webserver-student-id</​note>​
 +
 +  * Stergem pod-ul creat anterior.
 +
 +<​note>​kubectl delete pod webserver-student-id
 +
 +kubectl get po -o wide # Should output "No resources found."</​note>​
 +
 +  * Cream un pod ce contine doua containere
 +
 +<​note>​kubectl apply -f pod02.yaml
 +
 +kubectl get po -o wide
 +
 +kubectl describe pod webserver</​note>​
 +
 +  * Rulati comenzile urmatoare una cate una si observati ca va aflati in containere diferite ale aceluiasi pod.
 +
 +<​note>​kubectl exec -it webserver -c webwatcher -- /bin/bash
 +
 +root@webserver:/#​ cat /​etc/​os-release
 +
 +kubectl exec -it webserver -c webserver -- /bin/bash
 +
 +root@webserver:/#​ cat /​etc/​os-release
 +</​note>​
 +  * Stergem ceea ce am creat folosind comanda de mai jos
 +
 +<​note>​kubectl delete -f pod02.yaml</​note>​
 +
 +  * Cream pod-ul 3 folosind fisierul pod03.yaml. Avem dooua containere care impart acelasi volum.
 +
 +<​note>​kubectl apply -f pod03.yaml</​note>​
 +
 +  * Observati in definitia pod-ului cum este montat volumul html in cele doua containere
 +  * Mai departe verificam faptul ca aceleasi date sunt prezente in ambele containere
 +
 +<​note>​kubectl exec webserver -c c1 -- /bin/cat /​usr/​share/​nginx/​html/​index.html
 +
 +kubectl exec webserver -c c2 -- /bin/cat /​html/​index.html
 +</​note>​
 +  * Stergem pod-ul creat anterior
 +
 +<​note>​kubectl delete pod webserver</​note>​
 +
 +  * Pentru partea a 2-a (din 3) a laboratorului,​ rulati comanda:
 +
 +<​note>​cd ../​Laborator2</​note>​
 +
 +==== 5.2. Deployments,​ stateless/​stateful ====
 +
 +=== Deployments - de obicei folosit de aplicatii stateless ===
 +
 +  * Creeaza primul tau deployment folosind commanda urmatoare:
 +
 +<​note>​kubectl apply -f deploy-01.yaml</​note>​
 +
 +  * Observam detaliile deployment-ului
 +
 +<​note>​kubectl get deployments
 +
 +kubectl get pods
 +
 +kubectl get replicaset</​note>​
 +
 +  * Scalam deployment-ul in sus, crescand numarul de replici
 +<​note>​kubectl scale deployments/​nginx-deployment --replicas=4
 +
 +kubectl get pods -o wide # vom vedea 4 pod-uri</​note>​
 +  * Scalam deployment-ul in jos. Reducem numarul de pod-uri
 +<​note>​kubectl scale deployments/​nginx-deployment --replicas=2
 +
 +kubectl get pods -o wide</​note> ​
 +
 +  * Schimbam imaginea folosita in deployment utilizand comanda urmatoare:
 +
 +<​note>​kubectl set image  deployments/​nginx-deployment nginx=nginx:​1.9.1</​note>​
 +
 +  * Facem revert la deployment-ul anterior cu imaginea de docker anterioara
 +
 +<​note>​kubectl rollout undo deployments/​nginx-deployment
 +
 +kubectl rollout status deployments/​nginx-deployment ​
 +
 +kubectl describe deploy nginx-deployment
 +</​note>​
 +
 +  * Stergem deployment-ul
 +
 +<​note>​kubectl delete deployment nginx-deployment</​note>​
 +
 +=== Statefulset - aplicatii stateful ===
 +
 +  * Pe fiecare masina student exista instalat si configurat nfs server cu export-urile:​
 +
 +<​note>/​exports/​data-0001
 +/​exports/​data-0002</​note>​
 +
 +  * Verificam ca functioneaza mount-urile:​
 +
 +<​note>​sudo showmount -e localhost</​note>​
 +
 +  * Fiecare student va folosi propria adresa ip, mai departe in cadrul acestui laborator.
 +  * Adresa ip poate fi obtinuta folosind comanda de mai jos
 +
 +<​note>​ip -f inet addr show ens3</​note>​
 +
 +  * Editati fisierele nfs-0001.yaml si nfs-0002.yaml,​ adaugand adresa ip proprie in campul spec.nfs.server si actualizati campul metadata.name cu id-ul de student aferent.
 +
 +  * Cream volume persistente astfel:
 +
 +<​note>​kubectl apply -f nfs-0001.yaml
 +
 +kubectl apply -f nfs-0002.yaml</​note>​
 +
 +  * Observam volumele create
 +
 +<​note>​kubectl get pv | grep studentid
 +
 +kubectl describe pv <​pv_name></​note>​
 +
 +  * Cream un statefulset folosind comanda de mai jos:
 +
 +<​note>​kubectl apply -f statefulset-01.yaml</​note>​
 +
 +  * Observam statefulset-ul creat
 +
 +<​note>​kubectl get statefulset
 +
 +kubectl describe statefulset
 +
 +kubectl get pods</​note>​
 +
 +  * Verificam ca datele de pe disk sunt disponibile in container
 +
 +  * Scriem date in volumele de pe disk
 +
 +echo 'Hello World' ​ /​exports/​data-0001/​index.html
 +echo "Hello $USER" > /​exports/​data-0002/​index.html
 +
 +  * Verificam in pod-uri. Comenzile urmatoare ar trebui sa afiseze continutul fisierului index.html de pe disk
 +
 +<​note>​kubectl exec -it web-0 -- cat /​usr/​share/​nginx/​html/​index.html
 +
 +kubectl exec -it web-1 -- cat /​usr/​share/​nginx/​html/​index.html</​note>​
 +
 +  * Cream un serviciu care sa acceseze statefulset-ul
 +
 +<​note>​kubectl create -f service.yaml</​note>​
 +
 +  * Observam cum serviciul se conecteaza la backend (campul Endpoints:)
 +
 +<​note>​kubectl describe svc nginx</​note>​
 +
 +  * Curatam mediul
 +
 +<​note>​kubectl delete -f statefulset-01.yaml</​note>​
 +
 +  * Trecem la urmatorea parte din laborator
 +
 +<​note>​cd ../​Laborator3</​note>​
 +
 +==== 5.3. Daemonsets ====
 +
 +  * Daemonset-urile sunt resurse stateless, folosite pentru a putea rula, spre exemplu, un proces pe toate nodurile din cluster.
 +  * Daemonset-urile se asigura ca anumite nod-uri Kubernetes sau chiar toate ruleaza o copie a unui pod.
 +  * Editam continutul fisierului daemonset.yaml,​ actualizand "​student[id]"​ cu id-ul corespunzator
 +
 +<​note>​vi daemonset.yaml</​note>​
 +
 +  * Aplicam fisierul "​daemonset.yaml"​
 +
 +<​note>​kubectl apply -f daemonset.yaml</​note>​
 +
 +  * Verificam ca pod-urile au pornit. Vom vedea ca s-au creat 3 pod-uri, cate unul pe fiecare worker node.
 +
 +<​note>​kubectl get pods -owide
 +kubectl describe daemonset daemonset-studentid</​note>​
 +
 +  * Editam fisierul "​daemonset.yaml",​ decomentam liniile 16,17 si 18 .
 +
 +<​note>​vi daemonset.yaml</​note>​
 +
 +  * Aplicam din nou fisierul "​daemonset.yaml"​
 +
 +<​note>​kubectl apply -f daemonset.yaml</​note>​
 +
 +  * Unordered List ItemVerificam starea daemonset-ului si a pod-urilor. Observam ca s-a creat un pod si pe nodul master.
 +
 +<​note>​kubectl get daemonset
 +kubectl get pods -owide</​note>​
 +
 +  * Incercati sa stergeti un pod creat de daemonset.
 +
 +<​note>​kubectl delete pod daemonset-student[id]-xxxxx</​note>​
 +
 +  * Curatam mediul
 +
 +<​note>​kubectl delete daemonset daemonset-student[id]</​note>​
 +sau
 +<​note>​kubectl delete -f daemonset.yaml</​note>​
  
devops/laboratoare/05.txt ยท Last modified: 2021/07/28 16:54 by bogdan.croitoru
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0