Skip to content

Commit 9e141d1

Browse files
committed
Merge branch 'master' into docs-rel-4-8-0
2 parents 8ac4447 + 33ee7b4 commit 9e141d1

File tree

15 files changed

+1601
-481
lines changed

15 files changed

+1601
-481
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
partial_category: capi-image-builder
3+
partial_name: build-custom-image-intro
4+
---
5+
6+
1. Open a terminal session on your Linux machine and set your CAPI Image Builder version tag as a variable. This guide
7+
uses version 4.6.24 as an example. Refer to the CAPI Image Builder
8+
[Downloads](/downloads/capi-image-builder) page for the latest version.
9+
10+
```shell
11+
CAPI_IMAGE_BUILDER_VERSION=<capi-image-builder-version-tag>
12+
echo CAPI Image Builder version: $CAPI_IMAGE_BUILDER_VERSION
13+
```
14+
15+
```shell title="Example output"
16+
CAPI Image Builder version: v4.6.24
17+
```
18+
19+
2. Download the CAPI Image Builder image.
20+
21+
<Tabs groupId="container-tech">
22+
23+
<TabItem value="Docker" label="Docker">
24+
25+
```shell
26+
docker pull us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder:$CAPI_IMAGE_BUILDER_VERSION
27+
```
28+
29+
</TabItem>
30+
31+
<TabItem value="Podman" label="Podman">
32+
33+
```shell
34+
podman pull us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder:$CAPI_IMAGE_BUILDER_VERSION
35+
```
36+
37+
</TabItem>
38+
39+
</Tabs>
40+
41+
3. Create an `output` directory to store the image files and set the required permissions.
42+
43+
```shell
44+
mkdir /home/$USER/output
45+
chmod a+rwx /home/$USER/output
46+
```
47+
48+
4. Navigate to the `output` directory.
49+
50+
```shell
51+
cd /home/$USER/output
52+
```

_partials/capi-image-builder/_download-capi-image-builder-repository.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ partial_name: download-capi-image-builder-repository
88
<TabItem value="Docker" label="Docker">
99

1010
```shell
11-
docker pull us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder:v4.6.23
11+
docker pull us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder:v4.6.24
1212
```
1313

1414
Confirm that the image was downloaded correctly.
@@ -19,15 +19,15 @@ partial_name: download-capi-image-builder-repository
1919

2020
```text hideClipboard title="Example output"
2121
REPOSITORY TAG IMAGE ID CREATED SIZE
22-
us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder v4.6.23 2adff15eee2d 7 days ago 2.47 GB
22+
us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder v4.6.24 2adff15eee2d 7 days ago 2.09GB
2323
```
2424

2525
</TabItem>
2626

2727
<TabItem value="Podman" label="Podman">
2828

2929
```shell
30-
podman pull us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder:v4.6.23
30+
podman pull us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder:v4.6.24
3131
```
3232

3333
Confirm that the image was downloaded correctly.
@@ -38,7 +38,7 @@ partial_name: download-capi-image-builder-repository
3838

3939
```text hideClipboard title="Example output"
4040
REPOSITORY TAG IMAGE ID CREATED SIZE
41-
us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder v4.6.23 2adff15eee2d 7 days ago 2.47 GB
41+
us-docker.pkg.dev/palette-images/palette/imagebuilder/capi-builder v4.6.24 2adff15eee2d 7 days ago 2.09GB
4242
```
4343

4444
</TabItem>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
partial_category: capi-image-builder
3+
partial_name: ssh-vm
4+
---
5+
6+
Locate the new Rocky image VM in your VMware vSphere environment. Right-click the VM and select **Clone > Clone to
7+
Template**.
8+
9+
:::tip
10+
11+
Once the image is built, you can connect to the image via SSH. The following steps are based on guidance from the
12+
[Image Builder Book](https://image-builder.sigs.k8s.io/capi/providers/vsphere#accessing-remote-vms).
13+
14+
<details>
15+
16+
<summary> Connect to image VM with SSH </summary>
17+
18+
1. On a machine with [govc](https://github.com/vmware/govmomi/tree/main/govc) installed and configured with your
19+
VMware vSphere credentials, clone the
20+
[Kubernetes Image Builder repository](https://github.com/kubernetes-sigs/image-builder).
21+
22+
2. Navigate to the `capi` directory of the Kubernetes Image Builder repository.
23+
24+
```shell
25+
cd ./image-builder/images/capi/
26+
```
27+
28+
3. Run the Kubernetes Image Builder `image-govc-cloudinit.sh` script and pass in the `image_name` of your Rocky
29+
image VM as specified in the `imageconfig` file. This creates a snapshot of the image and updates it with the
30+
data located in the `cloudinit` directory. Ensure the VM is off before running the command.
31+
32+
```shell
33+
./hack/image-govc-cloudinit.sh <image_name>
34+
```
35+
36+
```shell title="Example output"
37+
image-govc-cloudinit: creating snapshot 'new'
38+
image-govc-cloudinit: initializing cloud-init data
39+
image-govc-cloudinit: creating snapshot 'cloudinit'
40+
```
41+
42+
4. Set read-write permissions for the `id_rsa.capi` file.
43+
44+
```shell
45+
chmod 600 cloudinit/id_rsa.capi
46+
```
47+
48+
5. Power on the Rocky image VM.
49+
50+
6. Connect to the VM via SSH using your `id_rsa.capi` key. Replace `<vm-ip>` with the IP of your Rocky image VM.
51+
52+
```shell
53+
ssh -i cloudinit/id_rsa.capi capv@<vm-ip>
54+
```
55+
56+
</details>
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
---
2+
partial_category: capi-image-builder
3+
partial_name: vm-prerequisites
4+
---
5+
6+
- An existing VM with an OS of Rocky Linux 8 or 9 installed. This VM will be used as the base of your image and must
7+
meet the following requirements:
8+
9+
- The following tools installed:
10+
11+
- [conntrack-tools](https://conntrack-tools.netfilter.org/)
12+
- [cloud-init](https://cloud-init.io/)
13+
- [cloud-utils-growpart](https://github.com/canonical/cloud-utils/)
14+
- [iptables](https://linux.die.net/man/8/iptables)
15+
- python2-pip
16+
- [python3](https://www.python.org/downloads/)
17+
18+
- A user of `builder` with a password of `builder`. This is required by the
19+
[vsphere-clone-builder](https://image-builder.sigs.k8s.io/capi/providers/vsphere#vsphere-clone-builder). The
20+
`builder` user must be granted passwordless sudo privileges.
21+
22+
<details>
23+
24+
<summary> `builder` user and password privileges </summary>
25+
26+
1. On your Rocky Linux VM, add a `builder` user.
27+
28+
```shell
29+
sudo useradd builder
30+
```
31+
32+
2. Set the password for the `builder` user to `builder`.
33+
34+
```shell
35+
echo 'builder:builder' | sudo chpasswd
36+
```
37+
38+
3. Assign passwordless sudo privileges to the `builder` user and assign the appropriate permissions.
39+
40+
```shell
41+
echo 'builder ALL=(ALL) NOPASSWD: ALL' | sudo tee /etc/sudoers.d/builder
42+
sudo chmod 0440 /etc/sudoers.d/builder
43+
```
44+
45+
</details>
46+
47+
- SSH password authentication enabled in `/etc/ssh/sshd_config` by setting `PasswordAuthentication` to `yes`. You must
48+
either restart `sshd` or reboot your system for the changes to take effect.
49+
50+
- SSH password authentication enabled for `cloud-init` by setting `ssh_pwauth` to `true`. This is required to prevent
51+
`cloud-init` from overwriting `PasswordAuthentication yes` in `/etc/ssh/sshd_config` when booting the cloned VM. We
52+
recommend creating a separate file that explicitly sets `ssh_pwauth: true`.
53+
54+
```shell
55+
sudo tee /etc/cloud/cloud.cfg.d/99-enable-ssh-pwauth.cfg << EOF
56+
ssh_pwauth: true
57+
EOF
58+
```
59+
60+
- [IPv4 packet forwarding](https://kubernetes.io/docs/setup/production-environment/container-runtimes/#prerequisite-ipv4-forwarding-optional)
61+
enabled.
62+
63+
- firewalld disabled.
64+
65+
```shell
66+
sudo systemctl disable --now firewalld
67+
```
68+
69+
- `/tmp` mounted to execute binaries and scripts.
70+
71+
<details>
72+
<summary> Check `/tmp` status </summary>
73+
74+
1. Check the mount status of `/tmp`. Look for a status of `noexec`.
75+
76+
```shell
77+
mount | grep '/tmp'
78+
```
79+
80+
```shell title="Example output" hideClipboard
81+
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noexec,relatime,size=2G)
82+
```
83+
84+
:::tip
85+
86+
If you receive an error, where `/tmp` is not displayed in the mount output, it is likely because it is a regular directory on the filesystem and not a separate mount.
87+
88+
Issue the following command to confirm the mount point of `/tmp`. If the `Mounted on` location is `/`, no action is required.
89+
90+
```shell
91+
df --human-readable /tmp
92+
```
93+
94+
```shell title="Example output" hideClipboard
95+
Filesystem Size Used Avail Use% Mounted on
96+
/dev/mapper/rl-root 70G 3.7G 67G 6% /
97+
```
98+
99+
:::
100+
101+
2. If `/tmp` has a status of `noexec`, use your preferred text editor to edit the file `/etc/fstab` and set `/tmp` to `exec`.
102+
103+
```shell
104+
vi /etc/fstab
105+
```
106+
107+
```shell title="Example output" hideClipboard {6}
108+
/dev/mapper/rl-root / xfs defaults 0 0
109+
UUID=3b068723-b40a-4c10-ac6d-00271cd4d3a4 /boot xfs defaults 0 0
110+
UUID=F867-A7CE /boot/efi vfat umask=0077,shortname=winnt 0 2
111+
/dev/mapper/rl-home /home xfs defaults 0 0
112+
/dev/mapper/rl-swap none swap defaults 0 0
113+
tmpfs /tmp tmpfs defaults,nosuid,nodev,exec,size=2G 0 0
114+
```
115+
116+
3. Remount all filesystems in `/etc/fstab`.
117+
118+
```shell
119+
sudo mount --all
120+
```
121+
122+
4. Confirm the mount status of `/tmp` is set to `exec`.
123+
124+
```shell
125+
mount | grep '/tmp'
126+
```
127+
128+
```shell title="Example output" hideClipboard
129+
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,exec,relatime,size=2G)
130+
```
131+
132+
</details>
133+
134+
- If your system has been hardened using a Security Technical Implementation Guide (STIG) policy, you may need to
135+
remediate the following:
136+
137+
- SELinux may prevent binaries from executing, including `cloud-init` scripts. We recommend setting the SELinux
138+
status to `permissive` or `disabled` until the image building process is complete.
139+
140+
<details>
141+
142+
<summary> Check SELinux status </summary>
143+
144+
1. Check the status of SELinux.
145+
146+
```shell
147+
getenforce
148+
```
149+
150+
```shell title="Example output" hideClipboard
151+
Enforcing
152+
```
153+
154+
2. If the status is `Enforcing`, use your preferred text editor to open the SELinux config file and set `SELINUX`
155+
to either `permissive` or `disabled`.
156+
157+
```shell
158+
vi /etc/selinux/config
159+
```
160+
161+
```shell title="Example output" hideClipboard {6}
162+
# This file controls the state of SELinux on the system.
163+
# SELINUX= can take one of these three values:
164+
# enforcing - SELinux security policy is enforced.
165+
# permissive - SELinux prints warnings instead of enforcing.
166+
# disabled - No SELinux policy is loaded.
167+
SELINUX=permissive
168+
# SELINUXTYPE= can take one of these three values:
169+
# targeted - Targeted processes are protected,
170+
# minimum - Modification of targeted policy. Only selected processes are protected.
171+
# mls - Multi Level Security protection.
172+
SELINUXTYPE=targeted
173+
```
174+
175+
</details>
176+
177+
- fapolicyd may prevent certain applications from executing, such as `containerd-shim-runc-v2`. We recommend
178+
disabling `fapolicyd` until the image building process is complete.
179+
180+
```shell
181+
sudo systemctl disable --now fapolicyd
182+
```
183+
184+
- A snapshot of your VM created once all other prerequisites are met. This is required by the
185+
[vsphere-clone-builder](https://image-builder.sigs.k8s.io/capi/providers/vsphere#vsphere-clone-builder).

0 commit comments

Comments
 (0)