0% found this document useful (0 votes)
128 views4 pages

TP Kubernetes (Minikube) : - Noureddine GRASSA-2019-2020

- The document describes how to set up a Kubernetes cluster using Minikube locally and complete various operations like deploying pods and services. - It shows commands to start Minikube, deploy Nginx pods with deployments and expose them via services, scale pods, edit files inside pods, and use the Kubernetes dashboard. - The last steps clean up resources by deleting pods, services and stopping Minikube.

Uploaded by

Lok . Com
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views4 pages

TP Kubernetes (Minikube) : - Noureddine GRASSA-2019-2020

- The document describes how to set up a Kubernetes cluster using Minikube locally and complete various operations like deploying pods and services. - It shows commands to start Minikube, deploy Nginx pods with deployments and expose them via services, scale pods, edit files inside pods, and use the Kubernetes dashboard. - The last steps clean up resources by deleting pods, services and stopping Minikube.

Uploaded by

Lok . Com
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

TP Kubernetes (minikube)

-Noureddine GRASSA-
2019-2020

Prerequis: Avoir installer minikube et kubectl


lien:https://kubernetes.io/docs/tasks/tools/install-kubectl/

-----------------------------------------Lancer le cluster sur minikube---------------------------------------


grassa@work-pc:~$ minikube start
😄 minikube v1.5.2 on Ubuntu 18.04 minikube v1.5.2 on Ubuntu 18.04
Automatically selected the 'kvm2' driver (alternates: [virtualbox none])
💾 Downloading driver docker-machine-driver-kvm2:
,…...
🏄 Done! kubectl is now configured to use "minikube" Done! kubectl is now configured to use "minikube"
⚠ /usr/local/bin/kubectl is version 1.13.1, and is incompatible with Kubernetes 1.16.2. You will
need to update /usr/local/bin/kubectl or use
'minikube kubectl' to connect with this cluster
grassa@work-pc:~$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-
key add -
OK
grassa@work-pc:~$ echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee
/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
grassa@work-pc:~$ sudo apt update
Atteint :1 http://fr.archive.ubuntu.com/ubuntu bionic InRelease
Atteint :2 https://repo.skype.com/deb stable InRelease
Atteint :3 http://fr.archive.ubuntu.com/ubuntu bionic-updates InRelease

grassa@work-pc:~$ kubectl cluster-info
Kubernetes master is running at https://192.168.39.44:8443
KubeDNS is running at https://192.168.39.44:8443/api/v1/namespaces/kube-system/services/kube-
dns:dns/proxy

grassa@work-pc:~$ kubectl config view


grassa@work-pc:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready master 11m v1.16.2

-------------------------------------------------Lancer un pod en mode deployment----------------------

grassa@work-pc:~$ kubectl run mynginxapp --image=nginx:latest --port=80


kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future
version. Use kubectl run --generator=run-pod/v1 or ku
bectl create instead.
deployment.apps/mynginxapp created

----------------------------------------------Creer un service a ce deployment------------------------------

grassa@work-pc:~$ kubectl expose deployment mynginxapp --type=NodePort


service/mynginxapp exposed
grassa@work-pc:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
mynginxapp-756586fc-kv75b 0/1 ContainerCreating 0 17s
grassa@work-pc:~$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
mynginxapp 1/1 1 1 77s
grassa@work-pc:~$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 24m
mynginxapp NodePort 10.102.204.114 <none> 80:32632/TCP 75s

-------------------------------------------Afficher l’URL et y acceder avec un navigateur----------------

grassa@work-pc:~$ minikube service mynginxapp --url


http://192.168.39.44:32632

-------------------------Lancement d’un autre pod et son service------------------------------------

grassa@work-pc:~$ kubectl run mynginxapp2 --image=nginx:latest –port=80


grassa@work-pc:~$ kubectl expose deployment mynginxapp2 --type=NodePort
service/mynginxapp2 exposed

-------------------------------Lancer 5 exemplaire de ce pod-------------------------------------

grassa@work-pc:~$ kubectl scale -n default deployment mynginxapp2 --replicas=5


deployment.apps/mynginxapp2 scaled
grassa@work-pc:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
deployment-586749695-hzh8c 0/1 CrashLoopBackOff 9 18m
mynginxapp-756586fc-kv75b 1/1 Running 1 15h
mynginxapp2-5567dc97f9-2mkkt 1/1 Running 0 14m
mynginxapp2-5567dc97f9-7jmnc 1/1 Running 0 14m
mynginxapp2-5567dc97f9-l8w9q 1/1 Running 0 18m
mynginxapp2-5567dc97f9-pg7w4 1/1 Running 0 14m
mynginxapp2-5567dc97f9-rkqpk 1/1 Running 0 15mer

-----------Creer d’un fichier YAML a partir de mynginxapp2---------------------------------------

grassa@work-pc:~$ kubectl get deployment mynginxapp2 -o yaml --export >


myappnginx2.yml
grassa@work-pc:~$ sed -i 's/myappnginx2/myappnginx3/g' myappnginx2.yml
grassa@work-pc:~$ mv myappnginx2.yml myappnginx3.yml

----------------Lancer un pod a partir d’un fichier YAML------------------------------------------------

grassa@work-pc:~$ kubectl create -f myappnginx3.yml


deployment.apps/mynginxapp3 created
grassa@work-pc:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
….
mynginxapp3-79c5f748fc-qsnvj 1/1 Running 0 34s
mynginxapp3-79c5f748fc-tjs5c 1/1 Running 0 33s
grassa@work-pc:~$ kubectl describe pods
grassa@work-pc:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
deployment-586749695-hzh8c 0/1 CrashLoopBackOff 13 33m
mynginxapp-756586fc-kv75b 1/1 Running 1 16h
mynginxapp3-79c5f748fc-qsnvj 1/1 Running 0 15m
mynginxapp3-79c5f748fc-tjs5c 1/1 Running 0 15m

-----------Acceder à un pod (nginx) et modifier le fichier index.html-------------------------------

grassa@work-pc:~$ kubectl exec -ti mynginxapp-756586fc-kv75b bash


root@mynginxapp-756586fc-kv75b:/#
root@mynginxapp-756586fc-kv75b:~# cd /usr/share/nginx/html/
root@mynginxapp-756586fc-kv75b:/usr/share/nginx/html# ls
50x.html index.html
root@mynginxapp-756586fc-kv75b:/usr/share/nginx/html# rm index.html
root@mynginxapp-756586fc-kv75b:/usr/share/nginx/html# echo "bonjour..." > index.html
root@mynginxapp-756586fc-kv75b:/usr/share/nginx/html# exit
grassa@work-pc:~$ minikube service mynginxapp –url
http://192.168.39.44:30142

----------------Afficher le contenu de index.html-----------------------------------------------------

grassa@work-pc:~$ curl http://192.168.39.44:30142


grassa@work-pc:~$ kubectl run srvweb --image=nginx:latest –port=80

----------------Creation d’un service LoadBalancer sur le port 80 du pod srvweb----------

grassa@work-pc:~$ kubectl expose deployment srvweb --name srvweb-80 --type


LoadBalancer --port 80 --protocol TCP
service/srvweb-80 exposed

------------------------------------Même chose mais sur le port 443 (https)---------------------------

grassa@work-pc:~$ kubectl expose deployment srvweb --name srvweb-443 --type


LoadBalancer --port 443 --protocol TCP
service/srvweb-443 exposed
grassa@work-pc:~$ kubectl get services
…..
srvweb-443 LoadBalancer 10.109.246.110 <pending> 443:31217/TCP 22s
srvweb-80 LoadBalancer 10.109.254.237 <pending> 80:30852/TCP 72s
grassa@work-pc:~$ minikube service srvweb-80 --url
http://192.168.39.44:30852

---------------------------------------------------Lancement d’un Dashboard-------------------------------


grassa@work-pc:~$ minikube addons list
- addon-manager: enabled
- dashboard: disabled
- default-storageclass: enabled
- efk: disabled
- freshpod: disabled
- gvisor: disabled
- heapster: disabled
- helm-tiller: disabled
- ingress: disabled
- ingress-dns: disabled
grassa@work-pc:~$ minikube dashboard
💾 Enabling dashboard ...
💾 Verifying dashboard health ...
💾 Launching proxy ...
💾 Verifying proxy health ...
💾 Opening http://127.0.0.1:38087/api/v1/namespaces/kubernetes-dashboard/services/
http:kubernetes-dashboard:/proxy/ in your default browser..
.
Ouverture dans une session de navigateur existante.

------------------------------------Effacer les Pods et les Services------------------------------------------


grassa@work-pc:~/$ kubectl delete service srvweb-443
service "srvweb-443" deleted
grassa@work-pc:~/$ kubectl delete service srvweb-80
service "srvweb-80" deleted
grassa@work-pc:~$ kubectl delete deployment srvweb

-------------------------------------Arrêter minikube --------------------------------------------------------

grassa@work-pc:~/$ minikube stop

You might also like