الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

معمل 18.1RH134, الفصل 18

Build an image-mode web server, update it and roll back

المستوى
صعب
90 دقيقة
الأجهزة
server1
الحالة
لم يبدأ

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

الهدف

Build a bootable container image with Apache, turn it into a KVM disk, boot a VM from it, then ship version 2 as an update — and roll it back.

قبل أن تبدأ

  • A RHEL 10 machine with KVM (virt-install) and at least 20 GiB free disk, registered, with access to registry.redhat.io (podman login registry.redhat.io).
  • A registry the VM can pull from. The easiest is a free account on quay.io (make the repository public), or a local registry on server1.
  • sudo dnf install -y container-tools virt-install.
  • In the tasks, replace quay.io/YOURNAME with your own registry path.

المهام

  1. Write a Containerfile that starts from registry.redhat.io/rhel10/rhel-bootc:10.0, installs httpd, enables it, opens nothing else, and serves a page version 1 from /usr/share/web/html.
  2. Build the image as quay.io/YOURNAME/web-bootc:1.0, test that httpd is in it, and push it. Also tag and push it as :prod.
  3. Make a qcow2 disk with bootc-image-builder. Add a user admin in wheel with your SSH key.
  4. Boot a VM bootc1 from the disk. Log in as admin and check the image with bootc status. Make sure the VM follows the tag :prod.
  5. Change the page to version 2, build :2.0, and push it as :prod. Update bootc1 and reboot it.
  6. Roll bootc1 back to version 1 and reboot again.

تحقّق من عملك

ssh admin@BOOTC1 'sudo bootc status'
curl -s http://BOOTC1/
ssh admin@BOOTC1 'rpm -q httpd; systemctl is-enabled httpd'
  • After task 5, curl prints version 2 and bootc status shows a rollback image.
  • After task 6, curl prints version 1.

تلميحات

اعرض التلميحات
  • /var is not updated by new images. Put the web page in /usr/share/web/html and point Apache there with a small config file in /etc/httpd/conf.d/.
  • bootc-image-builder runs as root and reads root's container storage: sudo podman pull the image first.
  • A VM made from the :1.0 disk follows :1.0. bootc switch quay.io/YOURNAME/web-bootc:prod makes it follow :prod.
  • On the KVM host, virsh domifaddr bootc1 shows the address of the VM. The libvirt network lets the host reach port 80 of the VM.

الحل

اعرض الحل
  1. The build folder.
    mkdir -p ~/web-bootc/html && cd ~/web-bootc
    echo "version 1" > html/index.html
    printf 'DocumentRoot "/usr/share/web/html"\n<Directory "/usr/share/web/html">\n    Require all granted\n</Directory>\n' > web.conf
    cat Containerfile
    FROM registry.redhat.io/rhel10/rhel-bootc:10.0
    RUN dnf -y install httpd && dnf clean all
    COPY web.conf /etc/httpd/conf.d/web.conf
    COPY html/ /usr/share/web/html/
    RUN systemctl enable httpd
  2. Build, test, push.
    podman login registry.redhat.io
    podman login quay.io
    podman build -t quay.io/YOURNAME/web-bootc:1.0 .
    podman run --rm quay.io/YOURNAME/web-bootc:1.0 rpm -q httpd
    podman push quay.io/YOURNAME/web-bootc:1.0
    podman tag quay.io/YOURNAME/web-bootc:1.0 quay.io/YOURNAME/web-bootc:prod
    podman push quay.io/YOURNAME/web-bootc:prod
  3. The disk image (as root).
    cat config.toml
    [[customizations.user]]
    name = "admin"
    key = "ssh-ed25519 AAAA...your-key"
    groups = ["wheel"]
    sudo podman pull quay.io/YOURNAME/web-bootc:prod
    mkdir -p output
    sudo podman run --rm -it --privileged --pull=newer --security-opt label=type:unconfined_t -v ./config.toml:/config.toml:ro -v ./output:/output -v /var/lib/containers/storage:/var/lib/containers/storage registry.redhat.io/rhel10/bootc-image-builder:latest --type qcow2 quay.io/YOURNAME/web-bootc:prod
  4. Boot the VM and check it.
    sudo cp output/qcow2/disk.qcow2 /var/lib/libvirt/images/bootc1.qcow2
    sudo virt-install --name bootc1 --memory 2048 --vcpus 2 --import --disk /var/lib/libvirt/images/bootc1.qcow2 --os-variant rhel10.0 --graphics none --noautoconsole
    sudo virsh domifaddr bootc1
    ssh admin@BOOTC1 'sudo bootc status'
    curl -s http://BOOTC1/
  5. Version 2 as an update.
    echo "version 2" > html/index.html
    podman build -t quay.io/YOURNAME/web-bootc:2.0 .
    podman push quay.io/YOURNAME/web-bootc:2.0
    podman tag quay.io/YOURNAME/web-bootc:2.0 quay.io/YOURNAME/web-bootc:prod
    podman push quay.io/YOURNAME/web-bootc:prod
    ssh admin@BOOTC1 'sudo bootc upgrade --apply'
    curl -s http://BOOTC1/
  6. Roll back.
    ssh admin@BOOTC1 'sudo bootc rollback && sudo systemctl reboot'
    curl -s http://BOOTC1/

ملاحظاتي

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

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

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