CodeBlanks Logo Icon CodeBlanks

Putting it together - multi-tier

Apply all resources to deploy the app.

Putting it together: the multi-tier deployment

All the files are ready. The deployment order: namespace, secret (by command), settings, database, API, web. Then it's verified that everything is ready:

kubectl apply -f k8s/00-namespace.yaml
kubectl create secret generic db-gizli -n magaza --from-literal=POSTGRES_PASSWORD="$DB_PAROLA"
kubectl apply -f k8s/
kubectl rollout status deploy/db deploy/api deploy/web -n magaza
kubectl get all -n magaza

End-to-end testing

The last step is seeing a request follow the web → API → database path end to end. A temporary container calls the API from inside the cluster; from the browser, the web service is opened:

kubectl run -n magaza deneme --rm -it --image=curlimages/curl:8.10.1 --restart=Never -- curl -s http://api:8000/saglik
{"durum":"ok","veritabani":"bagli"}
minikube service web -n magaza --url
http://192.168.49.2:30080

Practice Deploy and verify

Write four commands: apply the k8s/ folder; wait for the api deployment's rollout to finish in the magaza namespace; list all basic objects in magaza; print the web service's address with minikube service without opening a browser.

Starter code

terminal
# buraya yaz

Sample solution

terminal
kubectl apply -f k8s/
kubectl rollout status deployment/api -n magaza
kubectl get all -n magaza
minikube service web -n magaza --url

Expected output

namespace/magaza unchanged
configmap/api-ayar created
deployment.apps/db created
service/db created
deployment.apps/api created
deployment.apps/web created
service/web created
deployment "api" successfully rolled out
NAME                       READY   STATUS    RESTARTS   AGE
pod/api-7f8c9d6b5-abcde    1/1     Running   0          40s
pod/db-6c5d4b3a2-fghij     1/1     Running   0          41s
http://192.168.49.2:30080

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What happens if kubectl apply -f k8s/ is run a second time?

  • Everything is recreated
  • It errors
  • The database is deleted
  • Only changed objects are updated; the rest stay "unchanged" Correct answer

Explanation: apply is idempotent.

2 Delete the temporary pod when done.

Question
kubectl run -n magaza deneme ____ -it --image=curlimages/curl:8.10.1 --restart=Never -- curl -s http://api:8000/saglik
Answer
kubectl run -n magaza deneme --rm -it --image=curlimages/curl:8.10.1 --restart=Never -- curl -s http://api:8000/saglik

Explanation: --rm, together with -it, deletes the pod on exit.

3 Match.

Term Meaning
00-namespace.yaml Applied first
create secret Secret outside the repo
rollout status Wait for ready
curl http://api:8000 Internal end-to-end test

All lessons in Intermediate