kubectl get nodes # must show docker-desktop Readykubectl config current-context # must show docker-desktopkubectl version --short
Nothing else to install: kubectl is provided with Docker Desktop.
1. Build the image
From the project folder (projet10-kubernetes-deploiements):
powershell
docker build -t demo-k8s:1.0 ./app
With Docker Desktop, the local image is directly visible to the cluster (same Docker daemon). That is why the manifest uses imagePullPolicy: IfNotPresent.
kubectl get all # overviewkubectl get pods -o wide # Pods (IP, node, state)kubectl get deployment demo-webkubectl get service demo-webkubectl describe deployment demo-web # details + eventskubectl describe pod <nom-du-pod> # detail of a Pod (probes, image, events)kubectl get pods --watch # follow changes live (Ctrl+C to quit)
4. Test load balancing
Reload http://localhost:30080 several times: the Pod name changes.
for i in $(seq 1 10); do curl -s -H "Accept: application/json" http://localhost:30080; echo; done
5. Operate a Pod (exec, logs, port-forward)
powershell
kubectl logs <nom-du-pod> # logs of a Podkubectl logs -l app=demo-web --tail=20 # logs of ALL Pods of the labelkubectl exec -it <nom-du-pod> -- sh # open a shell in the Podkubectl exec <nom-du-pod> -- env # see the injected environment variableskubectl port-forward svc/demo-web 8080:80 # access the Service via http://localhost:8080
6. Change the configuration (ConfigMap / background)
# Manual scalingkubectl scale deployment demo-web --replicas=5kubectl get pods # 5 Pods nowkubectl scale deployment demo-web --replicas=3# Rolling update: change APP_VERSION in the ConfigMap thenkubectl apply -f k8s/configmap.yamlkubectl rollout restart deployment demo-webkubectl rollout status deployment demo-web # follows the progressive deployment# History and rollbackkubectl rollout history deployment demo-webkubectl rollout undo deployment demo-web # goes back to the previous version
8. Self-healing
powershell
kubectl get podskubectl delete pod <nom-du-pod> # we delete one by handkubectl get pods --watch # Kubernetes recreates one automatically
9. Cleanup
powershell
kubectl delete -f k8s/ # deletes service + deployment + configmap# or individually:kubectl delete service demo-webkubectl delete deployment demo-webkubectl delete configmap demo-config
Appendix A — minikube / kind
If you do not use Docker Desktop Kubernetes, the local image is not visible to the cluster: you must load it.
minikube:
powershell
minikube startminikube image load demo-k8s:1.0 # makes the image available in the clusterkubectl apply -f k8s/minikube service demo-web --url # gets the access URL
kind:
powershell
kind create clusterkind load docker-image demo-k8s:1.0 # loads the image into the clusterkubectl apply -f k8s/kubectl port-forward svc/demo-web 8080:80 # http://localhost:8080
Appendix B — troubleshooting
Symptom
Likely cause
Solution
ErrImagePull / ImagePullBackOff
The cluster cannot find the image
Check imagePullPolicy: IfNotPresent + image demo-k8s:1.0 built; on minikube/kind, load the image (Appendix A)
Pod in CrashLoopBackOff
The app crashes at startup
kubectl logs <pod> to read the error
Pod Pending
Insufficient resources
kubectl describe pod <pod> (Events section)
localhost:30080 unreachable
Service not created / wrong port
kubectl get svc; otherwise kubectl port-forward svc/demo-web 8080:80
kubectl does not answer
Wrong context
kubectl config use-context docker-desktop
Probe that fails
/health not reachable
Check port 5000 and the /health route
powershell
# Quick diagnosiskubectl get events --sort-by=.lastTimestampkubectl describe pod <nom-du-pod>
Course created by Dr. Haythem REHOUMA — Development and Deployment of Data Solutions