### Install Prerequisites and Prepare Host - Bash Script Source: https://context7.com/cledorze/metal3-demo/llms.txt Installs necessary packages like Ansible, Python, and kubectl, and configures the host system for the Metal3 demo. It supports openSUSE Leap and Ubuntu. This script also installs Ansible Galaxy roles and generates SSH keys for VM access. ```bash #!/bin/bash # Installs all required packages, Ansible, and configures the host system # Supports openSUSE Leap 15.6/16.0, Tumbleweed, and Ubuntu 22.04 cd metal3-demo ./01_prepare_host.sh # Output shows: # - OS detection and validation # - Package installation (ansible, python, jq, kubectl, etc.) # - Ansible galaxy role installation # - SSH key generation for VM access # Creates: ~/.ssh/id_ed25519 (if not exists) ``` -------------------------------- ### Makefile Automation - Makefile Source: https://context7.com/cledorze/metal3-demo/llms.txt Provides Makefile targets to automate the entire Metal3 demo environment setup process or execute individual setup steps. This simplifies the orchestration of the various setup scripts, allowing users to run all commands sequentially or choose specific stages. ```makefile # Run complete setup in sequence make all # Or run individual steps make install_requirements # Runs 01_prepare_host.sh make configure_host # Runs 02_configure_host.sh make launch_mgmt_cluster # Runs 04_launch_mgmt_cluster.sh ``` -------------------------------- ### Prepare Host Environment (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/setup/metal3-setup.md This script executes prerequisite package installations for the metal3-demo project. It assumes the user has already navigated into the cloned repository directory. ```shell cd metal3-demo ./01_prepare_host.sh ``` -------------------------------- ### Install GuestFS Tools and Customize Image (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/troubleshooting/provisioning.md Installs the libguestfs-tools package required for image customization. Then, it demonstrates how to use virt-customize to modify a virtual machine image by setting the root password. ```shell metal@metal3:~$ sudo apt-get install libguestfs-tools metal@metal3: ~$ sudo virt-customize -a --root-password password:PASSWORD ``` -------------------------------- ### BareMetalHost Manifest Structure Example Source: https://context7.com/cledorze/metal3-demo/llms.txt An example YAML structure for a BareMetalHost manifest, including metadata, spec with BMC details, and a corresponding Secret for BMC credentials. ```yaml # Example: ~/metal3-demo-files/baremetalhosts/controlplane-0.yaml apiversion: metal3.io/v1alpha1 kind: BareMetalHost metadata: name: controlplane-0 labels: cluster-role: control-plane spec: online: true bootMACAddress: "00:bc:1f:c3:8f:f0" bmc: address: redfish-virtualmedia://192.168.125.1:8000/redfish/v1/Systems/112815c5-b60f-4753-86d9-b25063c7bfc3 disableCertificateVerification: true credentialsName: controlplane-0-credentials preprovisioningNetworkDataName: controlplane-0-networkdata --- apiversion: v1 kind: Secret metadata: name: controlplane-0-credentials type: Opaque stringData: username: admin password: password ``` -------------------------------- ### Launch Management Cluster - Bash Script Source: https://context7.com/cledorze/metal3-demo/llms.txt Deploys the management cluster VM, including all Cluster API (CAPI) and Metal3 components. This script automates the creation of the VM, RKE2 installation, CAPI and Metal3 controller deployment, and Rancher Turtles setup. It also retrieves the kubeconfig for cluster management. ```bash #!/bin/bash # Deploys the management cluster VM with all CAPI and Metal3 components ./04_launch_mgmt_cluster.sh # Output shows: # - Management cluster VM creation # - RKE2 installation and startup # - CAPI controller deployment # - Metal3 Ironic deployment # - Rancher Turtles installation # - Kubeconfig retrieval to ~/.kube/config # Expected final output: # "Login to the management-cluster vm with 'ssh metal@192.168.125.99'" # Verify deployment kubectl get deployments -A # NAMESPACE NAME READY UP-TO-DATE # capi-system capi-controller-manager 1/1 1 # capm3-system capm3-controller-manager 1/1 1 # metal3-system baremetal-operator-controller-manager 1/1 1 # metal3-system metal3-metal3-ironic 1/1 1 ``` -------------------------------- ### Register and Monitor BareMetalHosts Source: https://context7.com/cledorze/metal3-demo/llms.txt Commands to apply BareMetalHost manifests and monitor their inspection and registration status. Includes commands for applying manifests and getting BareMetalHost resources. ```bash # Apply BareMetalHost manifests after management cluster is ready kubectl apply -f ~/metal3-demo-files/baremetalhosts # Monitor host inspection and registration kubectl get bmh -w # NAME STATE CONSUMER ONLINE ERROR AGE # controlplane-0 registering true 1m # controlplane-0 inspecting true 2m # controlplane-0 available true 5m # worker-0 available true 5m ``` -------------------------------- ### Deploy RKE2 Control Plane Nodes Source: https://context7.com/cledorze/metal3-demo/llms.txt Instructions to deploy the RKE2 control plane by navigating to example manifests, applying the control plane configuration, and monitoring the cluster creation process. ```bash # Navigate to example manifests cd ~/metal3-demo-files/example-manifests # Apply control plane configuration kubectl apply -f rke2-control-plane.yaml # Monitor cluster creation clusterctl describe cluster sample-cluster # Expected output after successful deployment: # NAME READY SEVERITY REASON SINCE MESSAGE # Cluster/sample-cluster True 22m # ├─ClusterInfrastructure - Metal3Cluster/sample-cluster True 27m # ├─ControlPlane - RKE2ControlPlane/sample-cluster True 22m # │ └─Machine/sample-cluster-chflc True 23m # Verify BareMetalHost consumption kubectl get bmh # NAME STATE CONSUMER ONLINE ERROR AGE # controlplane-0 provisioned sample-cluster-controlplane-xxx true 15m # worker-0 available true 15m ``` -------------------------------- ### Clone Metal3 Demo Repository (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/setup/metal3-setup.md This command clones the metal3-demo repository from GitHub. This is a necessary step to obtain the project files and scripts required for setup and deployment. ```shell git clone https://github.com/suse-edge/metal3-demo.git ``` -------------------------------- ### Customize Host Configuration Variables (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/setup/metal3-setup.md This example shows how to optionally customize host configuration by copying the default `extra_vars.yml` file and appending specific settings for a dual-stack deployment with static IPs. The `EXTRA_VARS_FILE` environment variable is then set to point to the customized file. ```shell cp extra_vars.yml ~ echo "libvirt_network_dhcp: false" >> ~/extra_vars.yml echo "libvirt_network_ipv6: true" >> ~/extra_vars.yml export EXTRA_VARS_FILE="~/extra_vars.yml" ``` -------------------------------- ### Inspect Metal3 Components and Logs Source: https://context7.com/cledorze/metal3-demo/llms.txt Guides on inspecting Metal3 components directly via SSH to the management cluster, checking Ironic API status, viewing Metal3 operator logs, and Metal3-Ironic conductor logs. ```bash # Check Ironic API directly ssh metal@192.168.125.99 baremetal node list baremetal node show baremetal introspection status # View Metal3 operator logs kubectl logs -n metal3-system deployment/baremetal-operator-controller-manager -f # Check Ironic logs kubectl logs -n metal3-system deployment/metal3-metal3-ironic -c ironic-conductor -f # View CAPI controller logs kubectl logs -n capm3-system deployment/capm3-controller-manager -f ``` -------------------------------- ### Static IP Configuration using nmstate Network Data Source: https://context7.com/cledorze/metal3-demo/llms.txt A YAML example of a Secret containing network data configured with static IP settings using nmstate, suitable for DHCP-less deployments. ```yaml # Static IP network data secret for DHCP-less deployments apiversion: v1 kind: Secret metadata: name: controlplane-0-networkdata type: Opaque stringData: networkData: | interfaces: - name: enp1s0 type: ethernet state: up mac-address: "00:bc:1f:c3:8f:f0" ipv4: address: - ip: "192.168.125.200" prefix-length: "24" enabled: true dhcp: false dns-resolver: config: server: - "192.168.125.1" routes: config: - destination: 0.0.0.0/0 next-hop-address: "192.168.125.1" next-hop-interface: enp1s0 ``` -------------------------------- ### Get Workload Cluster Kubeconfig and Nodes Source: https://context7.com/cledorze/metal3-demo/llms.txt Retrieves the kubeconfig for a workload cluster and lists the nodes within it. This is typically used after deploying a cluster to interact with it. ```bash # Get workload cluster kubeconfig clusterctl get kubeconfig sample-cluster > sample-cluster.kubeconfig kubectl --kubeconfig=sample-cluster.kubeconfig get nodes ``` -------------------------------- ### Configure Host with SLE Micro Local Image (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/setup/metal3-setup.md This sequence configures the host environment to use a locally provided SLE Micro image. It involves setting `OS_LOCAL_IMAGE` to the path of the raw image file and `EIB_REGISTRATION_CODE` for package installation, followed by running the image build script. ```shell export OS_LOCAL_IMAGE=/path/to/image.raw export EIB_REGISTRATION_CODE= ./03_build_images.sh ``` -------------------------------- ### Get BareMetalHost Status (Kubectl) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/setup/metal3-setup.md This command retrieves the status of all BareMetalHost resources in the Kubernetes cluster. It's used to monitor the registration and inspection progress of bare metal hosts, expecting them to reach an 'available' state. ```shell kubectl get bmh ``` -------------------------------- ### Configure Static IP Network Source: https://context7.com/cledorze/metal3-demo/llms.txt Configures a static IP addressing scheme for the external network by disabling DHCP and defining a specific IPv4 CIDR. It also specifies a starting IP for static assignments. ```bash # Disable DHCP for static IP testing cat > ~/static_ip_vars.yml < section ``` -------------------------------- ### Run Ansible Playbooks for Host Preparation and Configuration Source: https://context7.com/cledorze/metal3-demo/llms.txt Provides commands to execute Ansible playbooks for preparing hosts with verbose output, configuring hosts with custom variables, and setting up the management cluster. ```bash # Prepare host with verbose output export ANSIBLE_ROLES_PATH=./roles ansible-playbook -i inventories/localhost_inventory.yml \ playbooks/prepare_host.yml -vvv # Configure host with custom variables ansible-playbook -i inventories/localhost_inventory.yml \ -e @~/custom_vars.yml \ playbooks/configure_host.yml # Setup management cluster ansible-playbook -i inventories/localhost_inventory.yml \ -e @extra_vars.yml \ playbooks/setup_management_cluster.yml ``` -------------------------------- ### Access and Manage Virtual Machines Source: https://context7.com/cledorze/metal3-demo/llms.txt Provides instructions for SSHing into the management cluster, listing all virtual machines using `virsh`, accessing a VM's console, and viewing serial console logs. ```bash # SSH to management cluster ssh metal@192.168.125.99 # List all VMs export LIBVIRT_DEFAULT_URI="qemu:///system" virsh list --all # Access VM console virsh console controlplane-0 # View serial console logs sudo tail -f /var/log/libvirt/qemu/controlplane-0-serial0.log ``` -------------------------------- ### Troubleshoot IPMI Connection Issues (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/troubleshooting/provisioning.md Illustrates troubleshooting an IPMI connection error. The first command shows a failed attempt due to an incorrect session establishment, while the second command demonstrates a successful check of chassis power status. ```shell metal@metal3:~$ ipmitool -H 192.168.8.53 -I lanplus -U SCALE -P uj2bTkX chassis power status Error: Unable to establish IPMI v2 / RMCP+ session metal@metal3:~$ ipmitool -H 192.168.8.53 -I lanplus -U SCALE -P uj2bTkXV chassis power status Chassis Power is on ``` -------------------------------- ### Network Debugging with Libvirt and Bridge Tools Source: https://context7.com/cledorze/metal3-demo/llms.txt Commands for network debugging, including verifying libvirt network configurations, checking bridge interface status, and testing connectivity to the BMC emulator. ```bash # Verify libvirt network virsh net-list virsh net-dumpxml external # Check bridge configuration ip addr show m3-external bridge link show m3-external # Test connectivity to BMC emulator curl -k https://192.168.125.1:8000/redfish/v1/Systems/ ``` -------------------------------- ### Configure Host Environment - Bash Script Source: https://context7.com/cledorze/metal3-demo/llms.txt Sets up libvirt, networking, image caching, and the sushy-tools BMC emulator. This script can use default configurations or custom variables for specific deployments, such as dual-stack static IP configurations. It creates necessary libvirt networks, storage pools, and VM definitions. ```bash #!/bin/bash # Sets up libvirt, networking, image caching, and sushy-tools BMC emulator # Optional: Customize configuration before running # Default configuration ./02_configure_host.sh # With custom variables for dual-stack static IP deployment cp extra_vars.yml ~/my_vars.yml cat >> ~/my_vars.yml < capm3-ironic-75db6cbd85-dsqkl:/shared/html/images -n capm3-system -c ironic Update the image url in yaml url: http://boot.ironic.suse.baremetal/images/ ``` -------------------------------- ### Apply BareMetalHost Manifests (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/setup/metal3-setup.md This command applies the BareMetalHost manifests to the Kubernetes cluster. This action registers the bare metal hosts with the Metal3 system, allowing them to be managed. ```shell kubectl apply -f ~/metal3-demo-files/baremetalhosts ``` -------------------------------- ### Configure Host Environment (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/setup/metal3-setup.md This command executes the script responsible for configuring the host environment based on the project's requirements and any customized variables. This is a core step in preparing the system for cluster deployment. ```shell ./02_configure_host.sh ``` -------------------------------- ### Define Virtual Machine Flavors Source: https://context7.com/cledorze/metal3-demo/llms.txt Defines different virtual machine flavor profiles with specified memory, disk, and vCPU allocations for management, control plane, and worker nodes. ```yaml libvirt_flavors: management: memory: 8192 disk: 0 vcpu: 4 controlplane: memory: 4096 disk: 30 vcpu: 4 worker: memory: 4096 disk: 30 vcpu: 4 ``` -------------------------------- ### Build Custom OS Images - Bash Script Source: https://context7.com/cledorze/metal3-demo/llms.txt Prepares customized openSUSE Leap Micro or SUSE Linux Enterprise Micro images for use in the Metal3 environment. This script can use default images or specify a local image path and registration code for SLE Micro. The output is a customized OS image ready for deployment. ```bash #!/bin/bash # Prepares openSUSE Leap Micro or SUSE Linux Enterprise Micro images # Using default openSUSE Leap Micro 6.1 ./03_build_images.sh # Using SLE Micro 6.0 with registration export OS_LOCAL_IMAGE=/path/to/SLE-Micro.x86_64-5.5.0-Default-GM.raw export EIB_REGISTRATION_CODE=your_registration_code ./03_build_images.sh # Output: Customized OS image in /var/lib/libvirt/images/ # Image includes: RKE2, network configuration tools, Metal3 components ``` -------------------------------- ### Check Server Power Status with IPMI Tool (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/troubleshooting/provisioning.md Checks the power status of a server using the ipmitool command-line utility. This is often used for debugging registration errors related to BMC connectivity. ```shell metal@metal3:~$ ipmitool -H $ilo_ip -I lanplus -U $ilo_user -P $ilo_pwd chassis power status ``` -------------------------------- ### Configure BareMetalHost with Static IP using nmstate Source: https://github.com/cledorze/metal3-demo/blob/main/docs/setup/metal3-setup.md This snippet shows a BareMetalHost resource and an associated Secret containing nmstate network data. The network data configures a static IPv4 address, disables DHCP, and sets up DNS resolution and routing for the specified interface. This is used when libvirt DHCP is disabled. ```yaml apiVersion: metal3.io/v1alpha1 kind: BareMetalHost metadata: name: controlplane-0 labels: cluster-role: control-plane spec: online: true bootMACAddress: "00:bc:1f:c3:8f:f0" bmc: address: redfish-virtualmedia://192.168.125.1:8000/redfish/v1/Systems/112815c5-b60f-4753-86d9-b25063c7bfc3 disableCertificateVerification: true credentialsName: controlplane-0-credentials preprovisioningNetworkDataName: controlplane-0-networkdata --- aspiVersion: v1 kind: Secret metadata: name: controlplane-0-networkdata type: Opaque stringData: networkData: | interfaces: - name: enp1s0 type: ethernet state: up mac-address: "00:bc:1f:c3:8f:f0" ipv4: address: - ip: "192.168.125.200" prefix-length: "24" enabled: true dhcp: false dns-resolver: config: server: - "192.168.125.1" routes: config: - destination: 0.0.0.0/0 next-hop-address: "192.168.125.1" next-hop-interface: enp1s0 ``` -------------------------------- ### Create Non-Root User with Sudo Access (Shell) Source: https://github.com/cledorze/metal3-demo/blob/main/docs/setup/metal3-setup.md This snippet demonstrates how to create a new non-root user, grant them sudo privileges without requiring a password, and switch to that user. This is a common prerequisite for secure system administration. ```shell sudo useradd auser -m -s /bin/bash sudo echo "auser ALL=NOPASSWD: ALL" > /etc/sudoers.d/auser sudo su - auser ``` -------------------------------- ### Deploy RKE2 Worker Nodes Source: https://context7.com/cledorze/metal3-demo/llms.txt Commands to deploy RKE2 worker nodes by applying the worker node configuration and monitoring the full cluster status to ensure all nodes are provisioned and ready. ```bash # Apply worker node configuration kubectl apply -f rke2-agent.yaml # Monitor full cluster status clusterctl describe cluster sample-cluster # Expected output with workers: # NAME READY SEVERITY REASON SINCE MESSAGE # Cluster/sample-cluster True 25m # ├─ClusterInfrastructure - Metal3Cluster/sample-cluster True 30m # ├─ControlPlane - RKE2ControlPlane/sample-cluster True 25m # │ └─Machine/sample-cluster-chflc True 27m # └─Workers ``` -------------------------------- ### Inspect and Debug BareMetalHost Status Source: https://context7.com/cledorze/metal3-demo/llms.txt Commands for inspecting BareMetalHost status, checking provisioning states, accessing host consoles during inspection, and querying Ironic node status directly. ```bash # View detailed host status kubectl describe bmh controlplane-0 # Check provisioning status kubectl get bmh controlplane-0 -o jsonpath='{.status.provisioning.state}' # Access console during inspection export LIBVIRT_DEFAULT_URI="qemu:///system" virsh list virsh console controlplane-0 # Check Ironic node status directly ssh metal@192.168.125.99 baremetal node list baremetal node show ``` -------------------------------- ### Enable Verbose Script and Ansible Execution Source: https://context7.com/cledorze/metal3-demo/llms.txt Commands to run shell scripts with maximum verbosity (-vvv) and to enable debugging for Ansible playbooks. This is useful for troubleshooting. ```bash # Run scripts with maximum verbosity ./01_prepare_host.sh -vvv ./02_configure_host.sh -vvv ./04_launch_mgmt_cluster.sh -vvv # Enable Ansible debugging export ANSIBLE_DEBUG=1 export ANSIBLE_VERBOSITY=4 ansible-playbook -i inventories/localhost_inventory.yml playbooks/configure_host.yml ``` -------------------------------- ### Ansible Configuration - Environment Variables and Defaults - YAML Source: https://context7.com/cledorze/metal3-demo/llms.txt Defines default configuration variables for Ansible playbooks in the Metal3 demo environment, managed via `extra_vars.yml`. This file allows customization of VM user credentials, working directories, SSH keys, OS image sources, and network settings like IP address ranges. ```yaml # extra_vars.yml - Main configuration file # Override any variable by creating custom file and setting EXTRA_VARS_FILE vm_user: metal vm_user_plain_text_password: metal working_dir: "{{ lookup('env', 'HOME') }}/metal3-demo-files" # SSH access configuration public_key_file: "{{ lookup('env', 'HOME') }}/.ssh/id_ed25519.pub" vm_authorized_ssh_keys: - "{{ lookup('file', public_key_file) }}" # OS image selection os_image_url: https://download.opensuse.org/distribution/leap-micro/6.1/appliances/openSUSE-Leap-Micro.x86_64-Default.raw.xz os_local_image: "{{ lookup('env', 'OS_LOCAL_IMAGE') }}" # Network configuration external_network_cidr_v4: 192.168.125.0/24 external_network_cidr_v6: fd55::/64 management_cluster_public_ip: "{{ external_network_cidr_v4|ansible.utils.nthhost(99) }}" ``` -------------------------------- ### Custom MAC Address Generator Module (Python) Source: https://context7.com/cledorze/metal3-demo/llms.txt A custom Ansible module written in Python that generates sequential MAC addresses for virtual machine network interfaces. It takes a list of nodes and networks as input and registers the generated MAC addresses. ```python #!/usr/bin/python # roles/libvirt-setup/library/generate_macs.py # Generates unique MAC addresses for virtual bare metal hosts import math import random def generate_vm_interface_macs(nodes, networks): """Generate sequential MAC addresses for VM network interfaces.""" macs = [] count = len(nodes) * len(networks) # Generate base MAC with locally administered bit set low base_nums = [0x00, random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff)] base_mac = ':'.join(["%02x" % x for x in base_nums]) # Generate sequential MACs start = random.randint(0x00, 0xff) if (start + (count * 2)) > 0xff: start = 0xff - count * 2 for num in range(0, count * 2, 2): mac = start + num macs.append(base_mac + ":" + ("%02x" % mac)) # Map MACs to nodes and networks result = {} for node in nodes: result[node['name']] = {} for network in networks: result[node['name']][network['name']] = macs.pop(0) return result # Usage in Ansible playbook: # - name: Generate MAC addresses # generate_macs: # nodes: # - name: controlplane-0 # - name: worker-0 # networks: # - name: external # register: mac_addresses ``` -------------------------------- ### Deprovision Workload Cluster Source: https://context7.com/cledorze/metal3-demo/llms.txt Sequentially deprovisions a workload cluster by first deleting worker nodes and then the control plane. It includes commands to monitor the deprovisioning status of bare metal hosts. ```bash # Delete workers first kubectl delete -f rke2-agent.yaml # Wait for worker deprovisioning kubectl get bmh worker-0 -w # NAME STATE CONSUMER ONLINE ERROR AGE # worker-0 deprovisioning sample-cluster-workers-xxx false 5m # worker-0 available false 10m # Delete control plane kubectl delete -f rke2-control-plane.yaml # Verify all hosts return to available state kubectl get bmh # NAME STATE CONSUMER ONLINE ERROR AGE # controlplane-0 available false 20m # worker-0 available false 20m ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.