Skip to content

Commit beeaaf7

Browse files
committed
1.29 support and fixes:
- fix enabling password auth on newer ssh/cloud-config/ubuntu - ensure that the images are valid before writing to boot and image partitions - fix README
1 parent 2643394 commit beeaaf7

File tree

4 files changed

+64
-27
lines changed

4 files changed

+64
-27
lines changed

README.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ reinitialized to its initial state with just a single command.
2222
## Requirements
2323

2424
### Build Platform
25-
Linux or MacOS in arm64 or x86_64
26-
docker
27-
15G free space to contain initial, intermediate, and final images
25+
- Linux or MacOS on arm64 or x86_64
26+
- docker
27+
- 15G free space to contain initial, intermediate, and final images
2828

2929
### Nodes
3030
- Raspberri Pi 4b
@@ -36,9 +36,11 @@ docker
3636
Download a bootable Ubuntu image to be used as a base image for nodes. Latest
3737
LTS build for Raspberry Pi is the primary testing target here, so it shoud work
3838
best.
39+
3940
Write your build configuration to variables.cfg file. Use variables.cfg.example
4041
file and "Settings" section for referrence. Minimum required settings are IMAGE
4142
and K8S_VERSION.
43+
4244
While these two will allow you to build an image "just to give it a try", there
4345
is at least one more thing to configure if you plan to use your cluster for
4446
longer period of time. The cluster's certificates include IP address of master
@@ -47,34 +49,44 @@ address of master node changes, you might have to rebuild all the cluster certs
4749
and re-join the nodes. So it is strongly recommended that you create a static
4850
IP-to-MAC bidning in your DHCP server, and/or create a DNS name for your master
4951
node, and configure CONTROL_PLANE_ENDPOINT variable with this name.
52+
5053
More useful settings to improve the cluster maintainability, like setting a
5154
non-default password for login user, can be found under "Settings" section.
5255

5356
### Bootstrapping master node
5457
After you configured your variables.cfg, it is time to bootstrap your master
5558
node as the fist node in your cluster. If you are reusing variables.cfg from
5659
another cluster, make sure that KUBEADM_JOIN_STRING is absent or set to empty.
60+
5761
This is what tells the scripts that this is the first boot, and the SD card
5862
has to be partitioned for master-style layout, i.e. it should have an additional
5963
partition for master data.
64+
6065
Build the image with
66+
```
6167
bash ./build.sh
68+
```
69+
6270
Check the logs to make sure that all went well. There will be some errors caused
6371
by building it in docker+chroot - these will be followed by a message that the
6472
error can be safely ignored. Errors that do not have an explanation coming right
6573
after them may be a sign of a broken build. Please report them, or, even better,
6674
open a PR with a fix. Builds having such errors should not be used to update or
6775
install the nodes unless you know what you do.
76+
6877
After a successful build, an image at `images/bootable_image.img` is ready to
6978
be flashed on an SD card and used to boot your master node.
7079
Bootup and initialization would take 5-15 minutes depending on the speed of
7180
your SD card and internet connection (you will be downloading images for control
7281
panel).
82+
7383
After successfull boot, you will be able to log in to your new master node with
7484
the default user for your distriution (most likely "ubuntu"), and the default
7585
password (usually ubuntu), or your custom password if you set it.
86+
7687
Check /var/log/kubeadm.log to make sure the installation went well and grab the
7788
admin context from /etd/kubernetes/admin.conf.
89+
7890
A command to join new nodes to the cluster is stored at /usr/lib/k8r/join_string
7991
Update your variables.cfg file and set this command as a value of parameter
8092
KUBEADM_JOIN_STRING.
@@ -83,11 +95,13 @@ KUBEADM_JOIN_STRING.
8395
With KUBEADM_JOIN_STRING in variables.cfg file set to the value from previous
8496
step, re-run the build process by executing
8597
bash ./build.sh
98+
8699
This will build the image again with the new variables file (just injecting it
87100
is not implemented yet), creating a new images/bootable_image.img which you can
88101
use for initial bootstrap of the worker nodes, along with two more images,
89102
`images/boot.img.xz` and `images/image.img.xz` which can be used to upgrade, as
90103
well as to downgrade the nodes.
104+
91105
Now you can write bootable-image.img to SD cards of as many new nodes as you
92106
need, boot them, and have them joined your new cluster. Enjoy! :-)
93107

@@ -99,7 +113,8 @@ nodes, of by having the nodes download the updated image from HTTP location.
99113
To upgrade the nodes using local images, transfer updated images/boot.img.xz
100114
and images/image.img.xz so some location on the node, and write it to image
101115
partition with `update_image_partition.sh` script from `/usr/lib/k8r/tasks`
102-
directory, passing a directory where the images can be found as a parameter.
116+
directory, passing a directory where the images can be found as a parameter.
117+
103118
For example, if image.img.xz (boot.img.xz should be stored under the same
104119
location) can be found at `/home/ubuntu/new_images/image.img.xz` on the target
105120
node, then the command would look like this:
@@ -109,6 +124,7 @@ bash /usr/lib/k8r/tasks/update_image_partition.sh /home/ubuntu/new_images/
109124

110125
To upgrade the node from images from an HTTP, location, you need to have a
111126
variable HTTP_IMAGE_URL set to proper location in your `variables.cfg` file.
127+
112128
This can be preconfigured during the build step, and you can change it or set
113129
it on the target node anytime by editing `/usr/lib/k8s/variables.cfg` file.
114130
As an example, if you have your image.img.xz (same for boot.img.xz) available
@@ -211,19 +227,25 @@ various scripts
211227
without parameters, will try to download an image from HTTP_IMAGE_URL. To use
212228
an image from a local FS, use directory path as a parameter. The directory must
213229
contain both image.img.xz and boot.img.xz files.
230+
214231
`set_reinstall_mode.sh` - restart and reinstall the node. Boot and root
215232
filesystems will be rewritten using an initial image, resulting in a fresh node.
216233

217234
#### NOT intended for use by an operator:
218235
`install-docker.sh`: convenience script to install docker into build containers.
219236
Runs on build host.
237+
220238
`bootstrap_image.sh`: runs basic software installation and configuration during
221239
build process. Runs on build host.
240+
222241
`setup_partitions.sh`: creates required partitions inside image file. Runs on
223242
build host.
243+
224244
`reboot.sh`: utility wrapper used by task_runner's scripts to reboot the node.
245+
225246
`setup_node.sh`: run minimal preparations on the node during install process and
226247
trigger an appropriate next phase
248+
227249
`bootstrap_master.sh`: if node is expected to be a master, configure and start
228250
k8s control plane
229251

build.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,18 @@ else
145145
fi
146146
sed -i 's#ubuntu:!#ubuntu:'$PASSWD_HASH'#g' $K8R_IMAGE_MOUNT_DIR/etc/shadow
147147
echo "Enabling password authentication via ssh"
148-
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' $K8R_IMAGE_MOUNT_DIR/etc/ssh/sshd_config
148+
sed -i 's/^PasswordAuthentication no\ *$/PasswordAuthentication yes /g' $K8R_IMAGE_MOUNT_DIR/etc/ssh/sshd_config
149+
if [ "`grep -E '^PasswordAuthentication' $K8R_IMAGE_MOUNT_DIR/etc/ssh/sshd_config`" = "" ] ; then
150+
echo "No previous setting for Password Authentication was found. Adding now."
151+
echo >> $K8R_IMAGE_MOUNT_DIR/etc/ssh/sshd_config
152+
echo 'PasswordAuthentication yes' >> $K8R_IMAGE_MOUNT_DIR/etc/ssh/sshd_config
153+
fi
154+
ADDITIONAL_SSH_PASSWORD_CONFIG="`grep -ElR PasswordAuthentication $K8R_IMAGE_MOUNT_DIR/etc/ssh/sshd_config.d/`"
155+
if [ "$ADDITIONAL_SSH_PASSWORD_CONFIG" != "" ] ; then
156+
echo "Additional ssh password login config found in $ADDITIONAL_SSH_PASSWORD_CONFIG"
157+
echo "Removing the directive."
158+
sed -i 's/^PasswordAuthentication.*//g' $ADDITIONAL_SSH_PASSWORD_CONFIG
159+
fi
149160

150161
# FIXME: if the kernel gets updated by the script below (it shouldn't), then
151162
# FIXME: firmware updates will NOT be included into bootable_image.img

tasks/update_image_partition.sh

+24-20
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ if [ "$HTTP_IMAGE_URL" = "" -a "$LOCAL_IMAGE_PATH" = "" ] ; then
1616
exit 1
1717
fi
1818

19-
if [ "$LOCAL_IMAGE_PATH" != "" ] ; then
20-
if [ ! -r "$LOCAL_IMAGE_PATH"/image.img.xz ] ; then
21-
echo "ERROR: cannot read local image $LOCAL_IMAGE_PATH/image.img.xz. Exiting."
22-
elif [ ! -r "$LOCAL_IMAGE_PATH"/boot.img.xz ] ; then
23-
echo "ERROR: cannot read local boot image $LOCAL_IMAGE_PATH/boot.img.xz. Exiting."
24-
exit 1
25-
fi
26-
fi
27-
2819
ALL_DEV="`blkid`"
2920
BOOT_DEV=`echo "$ALL_DEV" | grep 'LABEL="system-boot"'| head -n 1 | awk -F':' {'print $1'} `
3021
IMAGE_DEV=`echo "$ALL_DEV" | grep 'LABEL="image"'| head -n 1 | awk -F':' {'print $1'} `
@@ -36,19 +27,32 @@ if [ "$LOCAL_IMAGE_PATH" = "" ] ; then
3627
curl -Lo /boot.img.xz $HTTP_IMAGE_URL/boot.img.xz
3728
echo "Downloading image from $HTTP_IMAGE_URL"
3829
curl -Lo /image.img.xz $HTTP_IMAGE_URL/image.img.xz
39-
#FIXME: The below writing options are duplicate: with empty $LOCAL_IMAGE_PATH
40-
#FIXME: they would be the same. Join these operations.
41-
echo "Writing boot image to boot partition $BOOT_DEV"
42-
unxz -v --stdout /boot.img.xz | dd of=$BOOT_DEV bs=100M
43-
echo "Writing image to image partition $IMAGE_DEV"
44-
unxz -v --stdout /image.img.xz | dd of=$IMAGE_DEV bs=100M
45-
else
46-
echo "Writing image $LOCAL_IMAGE_PATH/boot.img.xz to image partition $BOOT_DEV"
47-
unxz -v --stdout $LOCAL_IMAGE_PATH/boot.img.xz | dd of=$BOOT_DEV bs=100M
48-
echo "Writing image $LOCAL_IMAGE_PATH/image.img.xz to image partition $IMAGE_DEV"
49-
unxz -v --stdout $LOCAL_IMAGE_PATH/image.img.xz | dd of=$IMAGE_DEV bs=100M
5030
fi
5131

32+
if [ ! -r "$LOCAL_IMAGE_PATH"/image.img.xz ] ; then
33+
echo "ERROR: cannot read local installation image $LOCAL_IMAGE_PATH/image.img.xz. Exiting."
34+
exit 1
35+
fi
36+
if ! xz -t $LOCAL_IMAGE_PATH/image.img.xz ; then
37+
echo "ERROR: local installation image $LOCAL_IMAGE_PATH/image.img.xz is not an xz archive. Exiting."
38+
exit 1
39+
fi
40+
if [ ! -r "$LOCAL_IMAGE_PATH"/boot.img.xz ] ; then
41+
echo "ERROR: cannot read local boot image $LOCAL_IMAGE_PATH/boot.img.xz. Exiting."
42+
exit 1
43+
fi
44+
if ! xz -t $LOCAL_IMAGE_PATH/boot.img.xz ; then
45+
echo "ERROR: local boot image $LOCAL_IMAGE_PATH/boot.img.xz is not an xz archive. Exiting."
46+
exit 1
47+
fi
48+
49+
# Remote images are downloaded to / when LOCAL_IMAGE_PATH is empty, so the
50+
# following extraction procedure works for both local and remote cases.
51+
echo "Writing image $LOCAL_IMAGE_PATH/boot.img.xz to image partition $BOOT_DEV"
52+
unxz -v --stdout $LOCAL_IMAGE_PATH/boot.img.xz | dd of=$BOOT_DEV bs=100M
53+
echo "Writing image $LOCAL_IMAGE_PATH/image.img.xz to image partition $IMAGE_DEV"
54+
unxz -v --stdout $LOCAL_IMAGE_PATH/image.img.xz | dd of=$IMAGE_DEV bs=100M
55+
5256
echo "Verifying FS at target partitions $BOOT_DEV"
5357
fsck.vfat -a $BOOT_DEV || true
5458
echo "Verifying FS at target partition $IMAGE_DEV"

variables.cfg.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# MUST be present under current directory, must be an uncompressed image (not
33
# img.xz).
44
# Example:
5-
#IMAGE=ubuntu-22.04.2-preinstalled-server-arm64+raspi.img
5+
#IMAGE=ubuntu-22.04.4-preinstalled-server-arm64+raspi.img
66
IMAGE=
77

88
#K8S version to use
9-
K8S_VERSION=1.28.1
9+
K8S_VERSION=1.29.1
1010

1111
#While not mandatory, it is a good idea to have a DNS name or at least a fixed
1212
#IP-address associated with your master's MAC address. Otherwise, when your

0 commit comments

Comments
 (0)