متقدم
البحث فيالمعامل
طريقة البحث
  • ابحث عن مهمة أو أداة (lvm، selinux، ‎@podman)؛ وصفِّ حسب المستوى والكتاب أو الدورة.
  • مع مربع بحث فارغ، الفلتر وحده يعرض المعامل — مثلًا كل المعامل الصعبة لدورة واحدة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

معمل 13.1أدوات DevOps, الفصل 13

Speed drill: one release through all 10 everyday tools

المستوى
متوسط
60 دقيقة
الأجهزة
Linux or macOS with git, docker, kind, kubectl, helm, terraform, ansible, curl and ssh; optional az or aws CLI
الحالة
لم يبدأ

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

الهدف

Ship one small release from a Git commit to a running service, and use each of the 10 tools for the job it is best at. Every task should take one or two commands. Do the drill once slowly, then again with a timer: the goal is under 25 minutes, without looking at the solution.

قبل أن تبدأ

  • Install the tools (all are free). Make a local cluster: kind create cluster --name drill.
  • Make the folder ~/drill with an index.html that says version 1 and a 2-line Dockerfile (FROM nginx:1.27-alpine, COPY index.html /usr/share/nginx/html/).

المهام

  1. git — make a repository, commit both files, tag the commit v1.0.0 (annotated), and show the last commit in one line.
  2. docker — build the image drill-web:1.0.0, run it on port 8081, and stop it again after the test.
  3. curl — check the container: only the HTTP status code, then the response headers, with a 3-second timeout.
  4. kind / kubectl — load the image into the kind cluster (no registry), create a namespace drill, a deployment with 2 replicas, and a Service.
  5. kubectl — wait for the rollout, then reach the app with port-forward and curl. Show the pods with their node and IP.
  6. helm — install the chart bitnami/redis (or any small chart) in drill with one value changed from the command line; list releases; uninstall.
  7. kubectl — change index.html to version 2, build 1.0.1, load it, update the image of the deployment, watch the rollout, then roll back.
  8. terraform — with the local provider, write a file release.txt that contains the deployed version from a variable; apply with -var.
  9. ansible — run an ad-hoc command against localhost that shows the free disk space, and one that makes sure the folder /tmp/drill exists.
  10. ssh — run one remote command on a server (or localhost with your key) that prints the hostname and uptime, using a host entry from ~/.ssh/config.

تحقّق من عملك

git describe --tags
kubectl -n drill rollout history deploy/web
kubectl -n drill get deploy web -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'
cat release.txt
ls -d /tmp/drill
  • git describe prints v1.0.0.
  • The rollout history has at least 3 revisions (create, update, rollback).
  • After the rollback the image is drill-web:1.0.0 and curl shows version 1.
  • release.txt has the version you gave with -var.

تلميحات

اعرض التلميحات

الحل

اعرض الحل
  1. git.
    git init -q -b main && git add . && git commit -qm "drill web v1"
    git tag -a v1.0.0 -m "first release"
    git log -1 --oneline
  2. docker + 3. curl.
    docker build -t drill-web:1.0.0 .
    docker run -d --name drill -p 8081:80 drill-web:1.0.0
    curl -s -o /dev/null -w "%{http_code}\n" -m 3 localhost:8081
    200
    curl -sI -m 3 localhost:8081 | head -3
    docker rm -f drill
  3. and 5. kind + kubectl.
    kind load docker-image drill-web:1.0.0 --name drill
    kubectl create ns drill
    kubectl -n drill create deploy web --image=drill-web:1.0.0 --replicas=2 --port=80
    kubectl -n drill expose deploy web --port 80
    kubectl -n drill rollout status deploy/web
    kubectl -n drill get pods -o wide
    kubectl -n drill port-forward svc/web 8082:80 &
    curl -s localhost:8082
    version 1
  4. helm.
    helm repo add bitnami https://charts.bitnami.com/bitnami
    helm install cache bitnami/redis -n drill --set architecture=standalone
    helm list -n drill
    helm uninstall cache -n drill
  5. Update and roll back.
    echo "version 2" > index.html && docker build -t drill-web:1.0.1 . && kind load docker-image drill-web:1.0.1 --name drill
    kubectl -n drill set image deploy/web drill-web=drill-web:1.0.1
    kubectl -n drill rollout status deploy/web
    kubectl -n drill rollout undo deploy/web
    kubectl -n drill rollout history deploy/web

    kubectl create deploy names the container after the image (drill-web); check it with kubectl -n drill get deploy web -o yaml | grep -A2 containers if set image says the container is not found.

  6. terraform.
    main.tf
    variable "version_deployed" { type = string }
     
    resource "local_file" "release" {
      filename = "${path.module}/release.txt"
      content  = "web ${var.version_deployed}\n"
    }
    terraform init -input=false && terraform apply -auto-approve -var version_deployed=1.0.0
  7. ansible.
    ansible localhost -m command -a "df -h /"
    ansible localhost -m file -a "path=/tmp/drill state=directory"
  8. ssh.
    ~/.ssh/config
    Host lab
        HostName 127.0.0.1
        User youruser
        IdentityFile ~/.ssh/id_ed25519
    ssh lab 'hostname; uptime'
    kind delete cluster --name drill

ملاحظاتي

لا توجد ملاحظات بعد.

دروس هذا المعمل

الأوامر في هذا المعمل