Skip to content

Commit 2c18bc6

Browse files
Merge pull request #4156 from ggiguash/add_sample_kickstart_files
OCPBUGS-42864: Add sample kickstart files to microshift-release-info RPM and document usage
2 parents 4e28c3b + cf0564a commit 2c18bc6

File tree

5 files changed

+364
-0
lines changed

5 files changed

+364
-0
lines changed

packaging/kickstart/README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
The kickstart template files in this directory can be used for installing
2+
a host running MicroShift.
3+
4+
## Procedure Overview
5+
6+
* Start by configuring the [Prerequisites](#prerequisites).
7+
* Depending on the desired installation type, follow the instructions from one of
8+
the [RPM](#RPM), [Image Mode](#image-mode) or [OSTree](#OSTree) sections to
9+
create a working kickstart file from a template.
10+
* Create a virtual machine using the kickstart file from the previous step as
11+
described in [Create Virtual Machine](#create-virtual-machine)
12+
13+
14+
## Prepare Kickstart File
15+
16+
### Prerequisites
17+
18+
Install the `microshift-release-info` RPM package containing the sample kickstart
19+
files that are copied to the `/usr/share/microshift/kickstart` directory.
20+
21+
```bash
22+
sudo dnf install -y microshift-release-info
23+
```
24+
25+
Install the utilities used during the kickstart file creation.
26+
27+
```bash
28+
sudo dnf install -y openssl gettext
29+
```
30+
31+
Set variables pointing to secrets included in `kickstart.ks`.
32+
33+
* `PULL_SECRET` file contents are copied to `/etc/crio/openshift-pull-secret`
34+
at the post-install stage to authenticate OpenShift container registry access.
35+
* `USER_PASSWD` setting is used as an encrypted password for the `redhat` user
36+
for logging into the host.
37+
38+
Example commands setting the variables.
39+
40+
```bash
41+
export PULL_SECRET="$(cat ~/.pull-secret.json)"
42+
# Only the encrypted password will be included in kickstart
43+
PASSWD_TEXT=<my_redhat_user_plain_text_password>
44+
export USER_PASSWD="$(openssl passwd -6 "${PASSWD_TEXT}")"
45+
```
46+
47+
### RPM
48+
49+
The following variables need to be added for creating an RPM kickstart file.
50+
The activation keys and organization ID can be obtained at the [Activation Keys](https://console.redhat.com/insights/connector/activation-keys) site.
51+
They will be used for activating the Red Hat subscription during the installation.
52+
53+
> The subscription must include access to the `rhocp-4.x-for-rhel-9-$(uname -m)-rpms`
54+
> and `fast-datapath-for-rhel-9-$(uname -m)-rpms` RPM repositories.
55+
56+
* `RHSM_ORG` contains an RHSM organization ID for the subscription registration
57+
command in kickstart.
58+
* `RHSM_KEY` contains an RHSM activation key for the subscription registration
59+
command in kickstart.
60+
* `MICROSHIFT_VER` references the MicroShift version to install using the `4.y`
61+
format. Note that the latest available `.z` version will be installed.
62+
63+
Example commands setting the variables.
64+
65+
```bash
66+
export RHSM_ORG="$(cat ~/.rhsm-activation-org)"
67+
export RHSM_KEY="$(cat ~/.rhsm-activation-key)"
68+
export MICROSHIFT_VER=4.17
69+
```
70+
71+
Run the following command to create the `kickstart.ks` file to be used during
72+
the virtual machine installation.
73+
74+
```bash
75+
envsubst < \
76+
/usr/share/microshift/kickstart/kickstart-rpm.ks.template > \
77+
"${HOME}/kickstart.ks"
78+
```
79+
80+
### Image Mode
81+
82+
The following variables need to be added for creating an Image Mode kickstart file.
83+
84+
* `BOOTC_IMAGE_URL` contains a reference to the image to be installed using the
85+
[ostreecontainer](https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#ostreecontainer) kickstart command.
86+
* `AUTH_CONFIG` contents are copied to `/etc/ostree/auth.json` to authenticate
87+
access to the `BOOTC_IMAGE_URL` image. If no registry authentication is required,
88+
skip this setting.
89+
* `REGISTRY_CONFIG` contents are copied to `/etc/containers/registries.conf.d/999-microshift-registry.conf`
90+
to configure access to the registry containing the `BOOTC_IMAGE_URL` image.
91+
If no registry configuration is required, skip this setting.
92+
93+
Example commands setting the variables.
94+
95+
```bash
96+
export BOOTC_IMAGE_URL=quay.io/myorg/mypath/microshift-image:tag
97+
export AUTH_CONFIG="$(cat ~/.quay-auth.json)"
98+
export REGISTRY_CONFIG="$(cat ~/.quay-config.conf)"
99+
```
100+
101+
Run the following command to create the `kickstart.ks` file to be used during
102+
the virtual machine installation.
103+
104+
```bash
105+
envsubst < \
106+
/usr/share/microshift/kickstart/kickstart-bootc.ks.template > \
107+
"${HOME}/kickstart.ks"
108+
```
109+
110+
### OSTree
111+
112+
The following variables need to be added for creating an OSTree kickstart file.
113+
114+
* `OSTREE_SERVER_URL` contains an OSTree server URL passed to the
115+
[ostreesetup](https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#ostreesetup) kickstart command.
116+
* `OSTREE_COMMIT_REF` contains an OSTree commit reference to be installed from
117+
the server.
118+
* `AUTH_CONFIG` contents are copied to `/etc/ostree/auth.json` at the pre-install
119+
stage to authenticate access to the `OSTREE_SERVER_URL` server. If no server
120+
authentication is required, skip this setting.
121+
122+
Example commands setting the variables.
123+
124+
```bash
125+
export OSTREE_SERVER_URL="<http://my_ostree_server_url>"
126+
export OSTREE_COMMIT_REF="myostree_commit_reference"
127+
export AUTH_CONFIG="$(cat ~/.ostree-auth.json)"
128+
```
129+
130+
Run the following command to create the `kickstart.ks` file to be used during
131+
the virtual machine installation.
132+
133+
```bash
134+
envsubst < \
135+
/usr/share/microshift/kickstart/kickstart-ostree.ks.template > \
136+
"${HOME}/kickstart.ks"
137+
```
138+
139+
## Create Virtual Machine
140+
141+
Download a RHEL boot ISO image from https://developers.redhat.com/products/rhel/download.
142+
Copy the downloaded file to the `/var/lib/libvirt/images` directory.
143+
144+
Run the following commands to create a RHEL virtual machine with 2 cores, 2GB of
145+
RAM and 20GB of storage. The command uses the kickstart file prepared in the
146+
previous steps to install the RHEL operating system and MicroShift.
147+
148+
```bash
149+
VMNAME=microshift-host
150+
NETNAME=default
151+
152+
sudo virt-install \
153+
--name ${VMNAME} \
154+
--vcpus 2 \
155+
--memory 2048 \
156+
--disk path=/var/lib/libvirt/images/${VMNAME}.qcow2,size=20 \
157+
--network network=${NETNAME},model=virtio \
158+
--events on_reboot=restart \
159+
--location /var/lib/libvirt/images/rhel-9.4-$(uname -m)-boot.iso \
160+
--initrd-inject "${HOME}/kickstart.ks" \
161+
--extra-args "inst.ks=file://kickstart.ks" \
162+
--wait
163+
```
164+
165+
Log into the virtual machine using the `redhat:<password>` credentials.
166+
Run the following command to verify that all the MicroShift pods are up and running
167+
without errors.
168+
169+
```bash
170+
watch sudo oc get pods -A \
171+
--kubeconfig /var/lib/microshift/resources/kubeadmin/kubeconfig
172+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
lang en_US.UTF-8
2+
keyboard us
3+
timezone UTC
4+
text
5+
reboot
6+
7+
# Partition the disk with hardware-specific boot and swap partitions, adding an
8+
# LVM volume that contains a 10GB+ system root. The remainder of the volume will
9+
# be used by the CSI driver for storing data.
10+
zerombr
11+
clearpart --all --initlabel
12+
13+
# Create boot and swap partitions as required by the current hardware platform
14+
reqpart --add-boot
15+
16+
# Add an LVM volume group and allocate a system root logical volume
17+
part pv.01 --grow
18+
volgroup rhel pv.01
19+
logvol / --vgname=rhel --fstype=xfs --size=10240 --name=root
20+
21+
# Lock root user account
22+
rootpw --lock
23+
24+
# Configure network to use DHCP and activate on boot
25+
network --bootproto=dhcp --device=link --activate --onboot=on
26+
27+
%pre-install --log=/dev/console --erroronfail
28+
29+
# Create a container registry authentication file
30+
mkdir -p /etc/ostree/
31+
cat > /etc/ostree/auth.json <<'EOF'
32+
${AUTH_CONFIG}
33+
EOF
34+
35+
# Delete an empty file or set permissions
36+
if [ "$(wc -w < /etc/ostree/auth.json)" -eq 0 ] ; then
37+
rm -f /etc/ostree/auth.json
38+
else
39+
chmod 600 /etc/ostree/auth.json
40+
fi
41+
42+
# Create a container registry configuration file
43+
mkdir -p /etc/containers/registries.conf.d/
44+
cat > /etc/containers/registries.conf.d/999-microshift-registry.conf <<'EOF'
45+
${REGISTRY_CONFIG}
46+
EOF
47+
48+
# Delete an empty file or set permissions
49+
if [ "$(wc -w < /etc/containers/registries.conf.d/999-microshift-registry.conf)" -eq 0 ] ; then
50+
rm -f /etc/containers/registries.conf.d/999-microshift-registry.conf
51+
else
52+
chmod 644 /etc/containers/registries.conf.d/999-microshift-registry.conf
53+
fi
54+
55+
%end
56+
57+
# Pull a bootc image from a remote registry
58+
ostreecontainer --url ${BOOTC_IMAGE_URL}
59+
60+
%post --log=/dev/console --erroronfail
61+
62+
# Create 'redhat' user account
63+
useradd --password '${USER_PASSWD}' --groups wheel redhat
64+
65+
# Create an OpenShift pull secret file
66+
cat > /etc/crio/openshift-pull-secret <<'EOF'
67+
${PULL_SECRET}
68+
EOF
69+
chmod 600 /etc/crio/openshift-pull-secret
70+
71+
%end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
lang en_US.UTF-8
2+
keyboard us
3+
timezone UTC
4+
text
5+
reboot
6+
7+
# Partition the disk with hardware-specific boot and swap partitions, adding an
8+
# LVM volume that contains a 10GB+ system root. The remainder of the volume will
9+
# be used by the CSI driver for storing data.
10+
zerombr
11+
clearpart --all --initlabel
12+
13+
# Create boot and swap partitions as required by the current hardware platform
14+
reqpart --add-boot
15+
16+
# Add an LVM volume group and allocate a system root logical volume
17+
part pv.01 --grow
18+
volgroup rhel pv.01
19+
logvol / --vgname=rhel --fstype=xfs --size=10240 --name=root
20+
21+
# Lock root user account
22+
rootpw --lock
23+
24+
# Configure network to use DHCP and activate on boot
25+
network --bootproto=dhcp --device=link --activate --onboot=on
26+
27+
%pre-install --log=/dev/console --erroronfail
28+
29+
# Create an rpm-ostree authentication file
30+
mkdir -p /etc/ostree/
31+
cat > /etc/ostree/auth.json <<'EOF'
32+
${AUTH_CONFIG}
33+
EOF
34+
35+
# Delete an empty file or set permissions
36+
if [ "$(wc -w < /etc/ostree/auth.json)" -eq 0 ] ; then
37+
rm -f /etc/ostree/auth.json
38+
else
39+
chmod 600 /etc/ostree/auth.json
40+
fi
41+
42+
%end
43+
44+
# Pull an rpm-ostree image from a remote server
45+
ostreesetup --osname=rhel --url=${OSTREE_SERVER_URL} --ref=${OSTREE_COMMIT_REF} --nogpg
46+
47+
%post --log=/dev/console --erroronfail
48+
49+
# Create 'redhat' user account
50+
useradd --password '${USER_PASSWD}' --groups wheel redhat
51+
52+
# Create an OpenShift pull secret file
53+
cat > /etc/crio/openshift-pull-secret <<'EOF'
54+
${PULL_SECRET}
55+
EOF
56+
chmod 600 /etc/crio/openshift-pull-secret
57+
58+
%end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
lang en_US.UTF-8
2+
keyboard us
3+
timezone UTC
4+
text
5+
reboot
6+
7+
# Partition the disk with hardware-specific boot and swap partitions, adding an
8+
# LVM volume that contains a 10GB+ system root. The remainder of the volume will
9+
# be used by the CSI driver for storing data.
10+
zerombr
11+
clearpart --all --initlabel
12+
13+
# Create boot and swap partitions as required by the current hardware platform
14+
reqpart --add-boot
15+
16+
# Add an LVM volume group and allocate a system root logical volume
17+
part pv.01 --grow
18+
volgroup rhel pv.01
19+
logvol / --vgname=rhel --fstype=xfs --size=10240 --name=root
20+
21+
# Lock root user account
22+
rootpw --lock
23+
24+
# Configure network to use DHCP and activate on boot
25+
network --bootproto=dhcp --device=link --activate --onboot=on
26+
27+
# Register the host with RHSM
28+
rhsm --organization "${RHSM_ORG}" --activation-key "${RHSM_KEY}"
29+
30+
# Minimal package setup
31+
%packages
32+
@^minimal-environment
33+
%end
34+
35+
%post --log=/dev/console --erroronfail
36+
37+
# Create 'redhat' user account
38+
useradd --password '${USER_PASSWD}' --groups wheel redhat
39+
40+
# Install and configure MicroShift
41+
dnf install -y \
42+
--enablerepo rhocp-${MICROSHIFT_VER}-for-rhel-9-$(uname -m)-rpms \
43+
--enablerepo fast-datapath-for-rhel-9-$(uname -m)-rpms \
44+
microshift-${MICROSHIFT_VER}\*
45+
46+
systemctl enable microshift
47+
firewall-offline-cmd --zone=trusted --add-source=10.42.0.0/16
48+
firewall-offline-cmd --zone=trusted --add-source=169.254.169.1
49+
50+
# Create an OpenShift pull secret file
51+
cat > /etc/crio/openshift-pull-secret <<'EOF'
52+
${PULL_SECRET}
53+
EOF
54+
chmod 600 /etc/crio/openshift-pull-secret
55+
56+
%end

packaging/rpm/microshift.spec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ mkdir -p -m755 %{buildroot}%{_datadir}/microshift/release
322322
install -p -m644 assets/release/release-{x86_64,aarch64}.json %{buildroot}%{_datadir}/microshift/release
323323
mkdir -p -m755 %{buildroot}%{_datadir}/microshift/blueprint
324324
install -p -m644 packaging/blueprint/blueprint*.toml %{buildroot}%{_datadir}/microshift/blueprint
325+
mkdir -p -m755 %{buildroot}%{_datadir}/microshift/kickstart
326+
install -p -m644 packaging/kickstart/kickstart*.ks.template %{buildroot}%{_datadir}/microshift/kickstart
325327

326328
# spec validation files
327329
mkdir -p -m755 %{buildroot}%{_datadir}/microshift/spec
@@ -566,9 +568,11 @@ fi
566568
%dir %{_datadir}/microshift
567569
%dir %{_datadir}/microshift/release
568570
%dir %{_datadir}/microshift/blueprint
571+
%dir %{_datadir}/microshift/kickstart
569572

570573
%{_datadir}/microshift/release/release-{x86_64,aarch64}.json
571574
%{_datadir}/microshift/blueprint/blueprint*.toml
575+
%{_datadir}/microshift/kickstart/kickstart*.ks.template
572576

573577
%files selinux
574578
/var/lib/kubelet/pods
@@ -645,6 +649,9 @@ fi
645649
# Use Git command to generate the log and replace the VERSION string
646650
# LANG=C git log --date="format:%a %b %d %Y" --pretty="tformat:* %cd %an <%ae> VERSION%n- %s%n" packaging/rpm/microshift.spec
647651
%changelog
652+
* Sun Nov 10 2024 Gregory Giguashvili <[email protected]> 4.18.0
653+
- Add sample kickstart files to microshift-release-info RPM
654+
648655
* Fri Oct 25 2024 Pablo Acevedo Montserrat <[email protected]> 4.18.0
649656
- USHIFT-4715: Add gateway-api-release-info rpm
650657

0 commit comments

Comments
 (0)